From 63390309094e2b07838d3f790c85220bd9ab1e8c Mon Sep 17 00:00:00 2001 From: Willem Leuverink Date: Sun, 17 Nov 2024 16:02:41 +0100 Subject: [PATCH] Add dedicated php child process endpoint (#414) * add separate php endpoint * fix window test --- src/ChildProcess.php | 10 ++++++++-- tests/ChildProcess/ChildProcessTest.php | 16 ++++++++-------- tests/Windows/WindowTest.php | 5 ++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/ChildProcess.php b/src/ChildProcess.php index ff80a07..171210f 100644 --- a/src/ChildProcess.php +++ b/src/ChildProcess.php @@ -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 diff --git a/tests/ChildProcess/ChildProcessTest.php b/tests/ChildProcess/ChildProcessTest.php index a2d9259..7bd13b7 100644 --- a/tests/ChildProcess/ChildProcessTest.php +++ b/tests/ChildProcess/ChildProcessTest.php @@ -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']; }); @@ -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']; }); @@ -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 () { diff --git a/tests/Windows/WindowTest.php b/tests/Windows/WindowTest.php index 25dbafc..8cf21d6 100644 --- a/tests/Windows/WindowTest.php +++ b/tests/Windows/WindowTest.php @@ -1,13 +1,16 @@ andReturn(new WindowClass('main')); $window = Window::open() + ->setClient(new Client) ->id('main') ->title('milwad') ->titleBarStyle('milwad') @@ -43,7 +46,7 @@ expect($windowArray['maximizable'])->toBeTrue(); expect($windowArray['closable'])->toBeTrue(); expect($windowArray['fullscreen'])->toBeTrue(); - expect($windowArray['kiosk'])->toBeFalse(); + expect($windowArray['kiosk'])->toBeTrue(); expect($windowArray['autoHideMenuBar'])->toBeTrue(); });