Skip to content

Commit 8b342fd

Browse files
committed
flip arguments for consistency
1 parent ee53a67 commit 8b342fd

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/ChildProcess.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ChildProcess
1212

1313
public function __construct(protected Client $client) {}
1414

15-
public function start(string $alias, string|array $cmd, ?string $cwd = null, ?array $env = null): self
15+
public function start(string|array $cmd, string $alias, ?string $cwd = null, ?array $env = null): self
1616
{
1717
$this->alias = $alias;
1818

@@ -34,11 +34,11 @@ public function start(string $alias, string|array $cmd, ?string $cwd = null, ?ar
3434
return $this;
3535
}
3636

37-
public function artisan(string $alias, string|array $cmd, ?array $env = null): self
37+
public function artisan(string|array $cmd, string $alias, ?array $env = null): self
3838
{
3939
$cmd = [PHP_BINARY, 'artisan', ...(array) $cmd];
4040

41-
return $this->start($alias, $cmd, env: $env);
41+
return $this->start($cmd, $alias, env: $env);
4242
}
4343

4444
public function stop(string $alias): void
@@ -48,11 +48,11 @@ public function stop(string $alias): void
4848
])->json();
4949
}
5050

51-
public function message(string $alias, mixed $message): void
51+
public function message(mixed $message, string $alias): void
5252
{
5353
$this->client->post('child-process/message', [
54-
'alias' => $alias,
5554
'message' => json_encode($message),
55+
'alias' => $alias,
5656
])->json();
5757
}
5858
}

tests/ChildProcess/ChildProcessTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
});
1010

1111
it('can start a child process', function () {
12-
ChildProcess::start('some-alias', 'foo bar', 'path/to/dir', ['baz' => 'zah']);
12+
ChildProcess::start('foo bar', 'some-alias', 'path/to/dir', ['baz' => 'zah']);
1313

1414
Http::assertSent(function (Request $request) {
1515
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
@@ -21,7 +21,7 @@
2121
});
2222

2323
it('can start a artisan command', function () {
24-
ChildProcess::artisan('some-alias', 'foo:bar', ['baz' => 'zah']);
24+
ChildProcess::artisan('foo:bar', 'some-alias', ['baz' => 'zah']);
2525

2626
Http::assertSent(function (Request $request) {
2727
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
@@ -35,36 +35,36 @@
3535
it('can mark the process as persistent')->todo();
3636

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

41-
ChildProcess::start('some-alias', ['foo', 'baz']);
41+
ChildProcess::start(['foo', 'baz'], 'some-alias');
4242
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'baz']);
4343
});
4444

4545
it('accepts either a string or a array as artisan command argument', function () {
46-
ChildProcess::artisan('some-alias', 'foo:bar');
46+
ChildProcess::artisan('foo:bar', 'some-alias');
4747
Http::assertSent(fn (Request $request) => $request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:bar']);
4848

49-
ChildProcess::artisan('some-alias', ['foo:baz']);
49+
ChildProcess::artisan(['foo:baz'], 'some-alias');
5050
Http::assertSent(fn (Request $request) => $request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:baz']);
5151
});
5252

5353
it('sets the cwd to the base path if none was given', function () {
54-
ChildProcess::start('some-alias', ['foo', 'bar'], cwd: 'path/to/dir');
54+
ChildProcess::start(['foo', 'bar'], 'some-alias', cwd: 'path/to/dir');
5555
Http::assertSent(fn (Request $request) => $request['cwd'] === 'path/to/dir');
5656

57-
ChildProcess::start('some-alias', ['foo', 'bar']);
57+
ChildProcess::start(['foo', 'bar'], 'some-alias');
5858
Http::assertSent(fn (Request $request) => $request['cwd'] === base_path());
5959
});
6060

6161
it('filters double spaces when exploding a command string', function () {
62-
ChildProcess::start('some-alias', 'foo bar baz bak');
62+
ChildProcess::start('foo bar baz bak', 'some-alias');
6363
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'bar', 'baz', 'bak']);
6464
});
6565

6666
it('escapes spaces when passing a command array', function () {
67-
ChildProcess::start('some-alias', ['path/to/some executable with spaces.sh', '--foo', '--bar']);
67+
ChildProcess::start(['path/to/some executable with spaces.sh', '--foo', '--bar'], 'some-alias');
6868
Http::assertSent(fn (Request $request) => $request['cmd'] === ['path/to/some\ executable\ with\ spaces.sh', '--foo', '--bar']);
6969
});
7070

@@ -78,7 +78,7 @@
7878
});
7979

8080
it('can send messages to a child process', function () {
81-
ChildProcess::message('some-alias', 'some-message');
81+
ChildProcess::message('some-message', 'some-alias');
8282

8383
Http::assertSent(function (Request $request) {
8484
return $request->url() === 'http://localhost:4000/api/child-process/message' &&

0 commit comments

Comments
 (0)