Skip to content

Commit 7a4f407

Browse files
committed
add artisan shorthand
1 parent 1e673bb commit 7a4f407

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/ChildProcess.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ public function start(string $alias, array $cmd, ?string $cwd = null, ?array $en
2828
return $this;
2929
}
3030

31+
public function artisan(string $alias, array $cmd, ?array $env = null): object
32+
{
33+
$cmd = array_merge([PHP_BINARY, 'artisan'], $cmd);
34+
35+
return $this->start(
36+
$alias,
37+
$cmd,
38+
base_path(),
39+
$env
40+
);
41+
42+
$this->alias = $alias;
43+
44+
$cwd = $cwd ?? base_path();
45+
46+
$this->process = $this->client->post('child-process/start', [
47+
'alias' => $alias,
48+
'cmd' => $cmd,
49+
'cwd' => $cwd,
50+
'env' => $env,
51+
])->json();
52+
53+
return $this;
54+
}
55+
3156
public function stop(string $alias): void
3257
{
3358
$this->client->post('child-process/stop', [

tests/ChildProcess/ChildProcessTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,23 @@
2020
});
2121
});
2222

23-
it('can start a artisan command')->todo();
23+
it('can start a artisan command', function () {
24+
ChildProcess::artisan('some-alias', ['foo:bar'], ['baz' => 'zah']);
25+
26+
Http::assertSent(function (Request $request) {
27+
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
28+
$request['alias'] === 'some-alias' &&
29+
$request['cmd'] === [PHP_BINARY, 'artisan', 'foo:bar'] &&
30+
$request['cwd'] === base_path() &&
31+
$request['env'] === ['baz' => 'zah'];
32+
});
33+
});
2434

2535
it('can mark the process as persistent')->todo();
2636

27-
it('accepts either a string or a array as command input')->todo();
37+
it('start method accepts either a string or a array as command input')->todo();
38+
39+
it('artisan method accepts either a string or a array as command input')->todo();
2840

2941
it('sets the cwd to the base path if none was given', function () {
3042
ChildProcess::start('some-alias', ['foo', 'bar'], cwd: 'path/to/dir');

0 commit comments

Comments
 (0)