Skip to content

Commit c201b1b

Browse files
committed
remove exploding string commands
1 parent 2153f1c commit c201b1b

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/ChildProcess.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function start(
6161

6262
$process = $this->client->post('child-process/start', [
6363
'alias' => $alias,
64-
'cmd' => $this->explodeCommand($cmd),
64+
'cmd' => (array) $cmd,
6565
'cwd' => $cwd ?? base_path(),
6666
'env' => $env,
6767
'persistent' => $persistent,
@@ -72,14 +72,14 @@ 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, ...$this->explodeCommand($cmd)];
75+
$cmd = [PHP_BINARY, ...(array) $cmd];
7676

7777
return $this->start($cmd, $alias, env: $env, persistent: $persistent);
7878
}
7979

8080
public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
8181
{
82-
$cmd = ['artisan', ...$this->explodeCommand($cmd)];
82+
$cmd = ['artisan', ...(array) $cmd];
8383

8484
return $this->php($cmd, $alias, env: $env, persistent: $persistent);
8585
}
@@ -126,13 +126,4 @@ protected function fromRuntimeProcess($process): static
126126

127127
return $this;
128128
}
129-
130-
private function explodeCommand(string|array $cmd): array
131-
{
132-
if (is_iterable($cmd)) {
133-
return $cmd;
134-
}
135-
136-
return array_values(array_filter(explode(' ', $cmd)));
137-
}
138129
}

tests/ChildProcess/ChildProcessTest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Http::assertSent(function (Request $request) {
2626
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
2727
$request['alias'] === 'some-alias' &&
28-
$request['cmd'] === ['foo', 'bar'] &&
28+
$request['cmd'] === ['foo bar'] &&
2929
$request['cwd'] === 'path/to/dir' &&
3030
$request['env'] === ['baz' => 'zah'];
3131
});
@@ -37,7 +37,7 @@
3737
Http::assertSent(function (Request $request) {
3838
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
3939
$request['alias'] === 'some-alias' &&
40-
$request['cmd'] === [PHP_BINARY, '-r', "'sleep(5);'"] &&
40+
$request['cmd'] === [PHP_BINARY, "-r 'sleep(5);'"] &&
4141
$request['cwd'] === base_path() &&
4242
$request['env'] === ['baz' => 'zah'];
4343
});
@@ -49,25 +49,25 @@
4949
Http::assertSent(function (Request $request) {
5050
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
5151
$request['alias'] === 'some-alias' &&
52-
$request['cmd'] === [PHP_BINARY, 'artisan', 'foo:bar', '--verbose'] &&
52+
$request['cmd'] === [PHP_BINARY, 'artisan', 'foo:bar --verbose'] &&
5353
$request['cwd'] === base_path() &&
5454
$request['env'] === ['baz' => 'zah'];
5555
});
5656
});
5757

5858
it('accepts either a string or a array as start command argument', function () {
5959
ChildProcess::start('foo bar', 'some-alias');
60-
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'bar']);
60+
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo bar']);
6161

6262
ChildProcess::start(['foo', 'baz'], 'some-alias');
6363
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'baz']);
6464
});
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'] === [PHP_BINARY, "-r 'sleep(5);'"]);
6969

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

@@ -87,11 +87,6 @@
8787
Http::assertSent(fn (Request $request) => $request['cwd'] === base_path());
8888
});
8989

90-
it('filters double spaces when exploding a command string', function () {
91-
ChildProcess::start('foo bar baz bak', 'some-alias');
92-
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'bar', 'baz', 'bak']);
93-
});
94-
9590
it('can stop a child process', function () {
9691
ChildProcess::stop('some-alias');
9792

0 commit comments

Comments
 (0)