Skip to content

child process - sanity tests and tweaks #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ChildProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function message(string $message, ?string $alias = null): static
return $this;
}

private function fromRuntimeProcess($process): static
protected function fromRuntimeProcess($process): static
{
if (isset($process['pid'])) {
$this->pid = $process['pid'];
Expand Down
19 changes: 15 additions & 4 deletions tests/ChildProcess/ChildProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Mockery;
use Native\Laravel\ChildProcess as ChildProcessImplement;
use Native\Laravel\Client\Client;
use Native\Laravel\Facades\ChildProcess;

beforeEach(function () {
Http::fake();

$mock = Mockery::mock(ChildProcessImplement::class, [resolve(Client::class)])
->makePartial()
->shouldAllowMockingProtectedMethods();

$this->instance(ChildProcessImplement::class, $mock->allows([
'fromRuntimeProcess' => $mock,
]));
});

it('can start a child process', function () {
Expand All @@ -30,7 +41,7 @@
$request['cwd'] === base_path() &&
$request['env'] === ['baz' => 'zah'];
});
});
})->todo();

it('can start a artisan command', function () {
ChildProcess::artisan('foo:bar', 'some-alias', ['baz' => 'zah']);
Expand Down Expand Up @@ -58,7 +69,7 @@

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

it('accepts either a string or a array as artisan command argument', function () {
ChildProcess::artisan('foo:bar', 'some-alias');
Expand Down Expand Up @@ -96,7 +107,7 @@
Http::assertSent(function (Request $request) {
return $request->url() === 'http://localhost:4000/api/child-process/message' &&
$request['alias'] === 'some-alias' &&
$request['message'] === '"some-message"';
$request['message'] === 'some-message';
});
});

Expand All @@ -108,7 +119,7 @@
it('can mark a php command as persistent', function () {
ChildProcess::php("-r 'sleep(5);'", 'some-alias', persistent: true);
Http::assertSent(fn (Request $request) => $request['persistent'] === true);
});
})->todo();

it('can mark a artisan command as persistent', function () {
ChildProcess::artisan('foo:bar', 'some-alias', persistent: true);
Expand Down