Skip to content

Commit

Permalink
Add dedicated php child process endpoint (#414)
Browse files Browse the repository at this point in the history
* add separate php endpoint

* fix window test
  • Loading branch information
gwleuverink authored Nov 17, 2024
1 parent a3bd955 commit 6339030
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
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 @@ -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)
->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();
expect($windowArray['autoHideMenuBar'])->toBeTrue();
});

Expand Down

0 comments on commit 6339030

Please sign in to comment.