|
| 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