Skip to content

Commit 6cf8488

Browse files
committed
add some sanity tests
1 parent 233675a commit 6cf8488

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/ChildProcess.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ public function start(string $alias, array $cmd, ?string $cwd = null, ?array $en
1616
{
1717
$this->alias = $alias;
1818

19+
$cwd = $cwd ?? base_path();
20+
1921
$this->process = $this->client->post('child-process/start', [
2022
'alias' => $alias,
2123
'cmd' => $cmd,
22-
'cwd' => base_path(),
24+
'cwd' => $cwd,
2325
'env' => $env,
2426
])->json();
2527

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
use Illuminate\Http\Client\Request;
4+
use Illuminate\Support\Facades\Http;
5+
use Native\Laravel\Facades\ChildProcess;
6+
7+
beforeEach(function () {
8+
Http::fake();
9+
});
10+
11+
it('can start a child process', function () {
12+
ChildProcess::start('some-alias', ['foo', 'bar'], 'path/to/dir', ['baz' => 'zah']);
13+
14+
Http::assertSent(function (Request $request) {
15+
return $request->url() === 'http://localhost:4000/api/child-process/start' &&
16+
$request['alias'] === 'some-alias' &&
17+
$request['cmd'] === ['foo', 'bar'] &&
18+
$request['cwd'] === 'path/to/dir' &&
19+
$request['env'] === ['baz' => 'zah'];
20+
});
21+
});
22+
23+
it('can start a artisan command', function () {})->todo();
24+
25+
it('accepts either a string or a array as command input')->todo();
26+
27+
it('sets the cwd to the base path if none was given', function () {
28+
ChildProcess::start('some-alias', ['foo', 'bar'], cwd: 'path/to/dir');
29+
Http::assertSent(fn (Request $request) => $request['cwd'] === 'path/to/dir');
30+
31+
ChildProcess::start('some-alias', ['foo', 'bar']);
32+
Http::assertSent(fn (Request $request) => $request['cwd'] === base_path());
33+
});
34+
35+
it('can stop a child process', function () {
36+
ChildProcess::stop('some-alias');
37+
38+
Http::assertSent(function (Request $request) {
39+
return $request->url() === 'http://localhost:4000/api/child-process/stop' &&
40+
$request['alias'] === 'some-alias';
41+
});
42+
});
43+
44+
it('can send messages to a child process', function () {
45+
ChildProcess::message('some-alias', 'some-message');
46+
47+
Http::assertSent(function (Request $request) {
48+
return $request->url() === 'http://localhost:4000/api/child-process/message' &&
49+
$request['alias'] === 'some-alias' &&
50+
$request['message'] === '"some-message"';
51+
});
52+
});

0 commit comments

Comments
 (0)