Skip to content

Commit 58a5539

Browse files
committed
add optional arg to make the process persistent
1 parent 8af94f6 commit 58a5539

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/ChildProcess.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ChildProcess
88
{
99
public function __construct(protected Client $client) {}
1010

11-
public function start(string|array $cmd, string $alias, ?string $cwd = null, ?array $env = null): self
11+
public function start(string|array $cmd, string $alias, ?string $cwd = null, ?array $env = null, ?bool $persistent = false): self
1212
{
1313
$cwd = $cwd ?? base_path();
1414

@@ -22,16 +22,17 @@ public function start(string|array $cmd, string $alias, ?string $cwd = null, ?ar
2222
'cmd' => $cmd,
2323
'cwd' => $cwd,
2424
'env' => $env,
25+
'persistent' => $persistent,
2526
])->json();
2627

2728
return $this;
2829
}
2930

30-
public function artisan(string|array $cmd, string $alias, ?array $env = null): self
31+
public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
3132
{
3233
$cmd = [PHP_BINARY, 'artisan', ...(array) $cmd];
3334

34-
return $this->start($cmd, $alias, env: $env);
35+
return $this->start($cmd, $alias, env: $env, persistent: $persistent);
3536
}
3637

3738
public function stop(string $alias): void

tests/ChildProcess/ChildProcessTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
});
3333
});
3434

35-
it('can mark the process as persistent')->todo();
36-
3735
it('accepts either a string or a array as start command argument', function () {
3836
ChildProcess::start('foo bar', 'some-alias');
3937
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'bar']);
@@ -81,3 +79,18 @@
8179
$request['message'] === '"some-message"';
8280
});
8381
});
82+
83+
it('can mark a process as persistent', function () {
84+
ChildProcess::start('foo bar', 'some-alias', persistent: true);
85+
Http::assertSent(fn (Request $request) => $request['persistent'] === true);
86+
});
87+
88+
it('can mark a artisan command as persistent', function () {
89+
ChildProcess::artisan('foo:bar', 'some-alias', persistent: true);
90+
Http::assertSent(fn (Request $request) => $request['persistent'] === true);
91+
});
92+
93+
it('marks the process as non-persistent by default', function () {
94+
ChildProcess::start('foo bar', 'some-alias');
95+
Http::assertSent(fn (Request $request) => $request['persistent'] === false);
96+
});

0 commit comments

Comments
 (0)