Skip to content

Commit 6339030

Browse files
authored
Add dedicated php child process endpoint (#414)
* add separate php endpoint * fix window test
1 parent a3bd955 commit 6339030

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/ChildProcess.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ public function start(
7272

7373
public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
7474
{
75-
$cmd = [PHP_BINARY, ...(array) $cmd];
75+
$process = $this->client->post('child-process/start-php', [
76+
'alias' => $alias,
77+
'cmd' => (array) $cmd,
78+
'cwd' => $cwd ?? base_path(),
79+
'env' => $env,
80+
'persistent' => $persistent,
81+
])->json();
7682

77-
return $this->start($cmd, $alias, env: $env, persistent: $persistent);
83+
return $this->fromRuntimeProcess($process);
7884
}
7985

8086
public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self

tests/ChildProcess/ChildProcessTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
ChildProcess::php("-r 'sleep(5);'", 'some-alias', ['baz' => 'zah']);
3636

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

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

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

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

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

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

8282
it('sets the cwd to the base path if none was given', function () {

tests/Windows/WindowTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?php
22

3+
use Native\Laravel\Client\Client;
34
use Native\Laravel\Facades\Window;
45
use Native\Laravel\Windows\Window as WindowClass;
56

67
it('test window', function () {
8+
Http::fake();
79
Window::shouldReceive('open')
810
->andReturn(new WindowClass('main'));
911

1012
$window = Window::open()
13+
->setClient(new Client)
1114
->id('main')
1215
->title('milwad')
1316
->titleBarStyle('milwad')
@@ -43,7 +46,7 @@
4346
expect($windowArray['maximizable'])->toBeTrue();
4447
expect($windowArray['closable'])->toBeTrue();
4548
expect($windowArray['fullscreen'])->toBeTrue();
46-
expect($windowArray['kiosk'])->toBeFalse();
49+
expect($windowArray['kiosk'])->toBeTrue();
4750
expect($windowArray['autoHideMenuBar'])->toBeTrue();
4851
});
4952

0 commit comments

Comments
 (0)