Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dedicated php child process endpoint #414

Merged
merged 4 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/ChildProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ public function start(

public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
{
$cmd = [PHP_BINARY, ...(array) $cmd];
$process = $this->client->post('child-process/start-php', [
'alias' => $alias,
'cmd' => (array) $cmd,
'cwd' => $cwd ?? base_path(),
'env' => $env,
'persistent' => $persistent,
])->json();

return $this->start($cmd, $alias, env: $env, persistent: $persistent);
return $this->fromRuntimeProcess($process);
}

public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
Expand Down
16 changes: 8 additions & 8 deletions tests/ChildProcess/ChildProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Mockery;

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-lowest - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-stable - ubuntu-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-lowest - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-stable - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-lowest - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-stable - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-lowest - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L11.* - prefer-stable - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-lowest - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.2 - L10.* - prefer-stable - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-lowest - windows-latest

The use statement with non-compound name 'Mockery' has no effect

Check warning on line 5 in tests/ChildProcess/ChildProcessTest.php

View workflow job for this annotation

GitHub Actions / P8.1 - L10.* - prefer-stable - windows-latest

The use statement with non-compound name 'Mockery' has no effect
use Native\Laravel\ChildProcess as ChildProcessImplement;
use Native\Laravel\Client\Client;
use Native\Laravel\Facades\ChildProcess;
Expand Down Expand Up @@ -35,9 +35,9 @@
ChildProcess::php("-r 'sleep(5);'", 'some-alias', ['baz' => 'zah']);

Http::assertSent(function (Request $request) {
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
return $request->url() === 'http://localhost:4000/api/child-process/start-php' &&
$request['alias'] === 'some-alias' &&
$request['cmd'] === [PHP_BINARY, "-r 'sleep(5);'"] &&
$request['cmd'] === ["-r 'sleep(5);'"] &&
$request['cwd'] === base_path() &&
$request['env'] === ['baz' => 'zah'];
});
Expand All @@ -47,9 +47,9 @@
ChildProcess::artisan('foo:bar --verbose', 'some-alias', ['baz' => 'zah']);

Http::assertSent(function (Request $request) {
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
return $request->url() === 'http://localhost:4000/api/child-process/start-php' &&
$request['alias'] === 'some-alias' &&
$request['cmd'] === [PHP_BINARY, 'artisan', 'foo:bar --verbose'] &&
$request['cmd'] === ['artisan', 'foo:bar --verbose'] &&
$request['cwd'] === base_path() &&
$request['env'] === ['baz' => 'zah'];
});
Expand All @@ -65,18 +65,18 @@

it('accepts either a string or a array as php command argument', function () {
ChildProcess::php("-r 'sleep(5);'", 'some-alias');
Http::assertSent(fn (Request $request) => $request['cmd'] === [PHP_BINARY, "-r 'sleep(5);'"]);
Http::assertSent(fn (Request $request) => $request['cmd'] === ["-r 'sleep(5);'"]);

ChildProcess::php(['-r', "'sleep(5);'"], 'some-alias');
Http::assertSent(fn (Request $request) => $request['cmd'] === [PHP_BINARY, '-r', "'sleep(5);'"]);
Http::assertSent(fn (Request $request) => $request['cmd'] === ['-r', "'sleep(5);'"]);
});

it('accepts either a string or a array as artisan command argument', function () {
ChildProcess::artisan('foo:bar', 'some-alias');
Http::assertSent(fn (Request $request) => $request['cmd'] === [PHP_BINARY, 'artisan', 'foo:bar']);
Http::assertSent(fn (Request $request) => $request['cmd'] === ['artisan', 'foo:bar']);

ChildProcess::artisan(['foo:baz'], 'some-alias');
Http::assertSent(fn (Request $request) => $request['cmd'] === [PHP_BINARY, 'artisan', 'foo:baz']);
Http::assertSent(fn (Request $request) => $request['cmd'] === ['artisan', 'foo:baz']);
});

it('sets the cwd to the base path if none was given', function () {
Expand Down
5 changes: 4 additions & 1 deletion tests/Windows/WindowTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

use Native\Laravel\Client\Client;
use Native\Laravel\Facades\Window;
use Native\Laravel\Windows\Window as WindowClass;

it('test window', function () {
Http::fake();
Window::shouldReceive('open')
->andReturn(new WindowClass('main'));

$window = Window::open()
->setClient(new Client)
simonhamp marked this conversation as resolved.
Show resolved Hide resolved
->id('main')
->title('milwad')
->titleBarStyle('milwad')
Expand Down Expand Up @@ -43,7 +46,7 @@
expect($windowArray['maximizable'])->toBeTrue();
expect($windowArray['closable'])->toBeTrue();
expect($windowArray['fullscreen'])->toBeTrue();
expect($windowArray['kiosk'])->toBeFalse();
expect($windowArray['kiosk'])->toBeTrue();
simonhamp marked this conversation as resolved.
Show resolved Hide resolved
expect($windowArray['autoHideMenuBar'])->toBeTrue();
});

Expand Down
Loading