-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
simonhamp
merged 20 commits into
NativePHP:feature/child-processes
from
gwleuverink:feature/child-processes
Oct 31, 2024
Merged
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6cf8488
add some sanity tests
gwleuverink 1e673bb
wip
gwleuverink 7a4f407
add artisan shorthand
gwleuverink 6e4f7db
allow passing either a string or array
gwleuverink ee53a67
correct return type
gwleuverink 8b342fd
flip arguments for consistency
gwleuverink bc46e8c
tidy - remove unused class properties
gwleuverink 8af94f6
remove unnecessary space escape
gwleuverink 58a5539
add optional arg to make the process persistent
gwleuverink e446a66
Merge branch 'feature/child-processes' into feature/child-processes
simonhamp 160b867
Update src/ChildProcess.php
62b8faf
feedback - tidy cwd default path
gwleuverink 246a236
stub out php command tests
gwleuverink 31d78ae
fix - tests after upstream merge
gwleuverink 8dbee1d
add php convenience method
gwleuverink 4e9ce39
wip - refactor
gwleuverink 2f76685
add phpdoc for facade methods
gwleuverink 2153f1c
Update src/Facades/ChildProcess.php
c201b1b
remove exploding string commands
gwleuverink a8bf775
fix - return a fresh instance from the facade each time
gwleuverink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
use Illuminate\Http\Client\Request; | ||
use Illuminate\Support\Facades\Http; | ||
use Native\Laravel\Facades\ChildProcess; | ||
|
||
beforeEach(function () { | ||
Http::fake(); | ||
}); | ||
|
||
it('can start a child process', function () { | ||
ChildProcess::start('some-alias', 'foo bar', 'path/to/dir', ['baz' => 'zah']); | ||
|
||
Http::assertSent(function (Request $request) { | ||
return $request->url() === 'http://localhost:4000/api/child-process/start' && | ||
$request['alias'] === 'some-alias' && | ||
$request['cmd'] === ['foo', 'bar'] && | ||
$request['cwd'] === 'path/to/dir' && | ||
$request['env'] === ['baz' => 'zah']; | ||
}); | ||
}); | ||
|
||
it('can start a artisan command', function () { | ||
ChildProcess::artisan('some-alias', 'foo:bar', ['baz' => 'zah']); | ||
|
||
Http::assertSent(function (Request $request) { | ||
return $request->url() === 'http://localhost:4000/api/child-process/start' && | ||
$request['alias'] === 'some-alias' && | ||
$request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:bar'] && | ||
$request['cwd'] === base_path() && | ||
$request['env'] === ['baz' => 'zah']; | ||
}); | ||
}); | ||
|
||
it('can mark the process as persistent')->todo(); | ||
|
||
it('accepts either a string or a array as start command argument', function () { | ||
ChildProcess::start('some-alias', 'foo bar'); | ||
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'bar']); | ||
|
||
ChildProcess::start('some-alias', ['foo', 'baz']); | ||
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'baz']); | ||
}); | ||
|
||
it('accepts either a string or a array as artisan command argument', function () { | ||
ChildProcess::artisan('some-alias', 'foo:bar'); | ||
Http::assertSent(fn (Request $request) => $request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:bar']); | ||
|
||
ChildProcess::artisan('some-alias', ['foo:baz']); | ||
Http::assertSent(fn (Request $request) => $request['cmd'] === [str_replace(' ', '\ ', PHP_BINARY), 'artisan', 'foo:baz']); | ||
}); | ||
|
||
it('sets the cwd to the base path if none was given', function () { | ||
ChildProcess::start('some-alias', ['foo', 'bar'], cwd: 'path/to/dir'); | ||
Http::assertSent(fn (Request $request) => $request['cwd'] === 'path/to/dir'); | ||
|
||
ChildProcess::start('some-alias', ['foo', 'bar']); | ||
Http::assertSent(fn (Request $request) => $request['cwd'] === base_path()); | ||
}); | ||
|
||
it('filters double spaces when exploding a command string', function () { | ||
ChildProcess::start('some-alias', 'foo bar baz bak'); | ||
Http::assertSent(fn (Request $request) => $request['cmd'] === ['foo', 'bar', 'baz', 'bak']); | ||
}); | ||
|
||
it('escapes spaces when passing a command array', function () { | ||
ChildProcess::start('some-alias', ['path/to/some executable with spaces.sh', '--foo', '--bar']); | ||
Http::assertSent(fn (Request $request) => $request['cmd'] === ['path/to/some\ executable\ with\ spaces.sh', '--foo', '--bar']); | ||
}); | ||
|
||
it('can stop a child process', function () { | ||
ChildProcess::stop('some-alias'); | ||
|
||
Http::assertSent(function (Request $request) { | ||
return $request->url() === 'http://localhost:4000/api/child-process/stop' && | ||
$request['alias'] === 'some-alias'; | ||
}); | ||
}); | ||
|
||
it('can send messages to a child process', function () { | ||
ChildProcess::message('some-alias', 'some-message'); | ||
|
||
Http::assertSent(function (Request $request) { | ||
return $request->url() === 'http://localhost:4000/api/child-process/message' && | ||
$request['alias'] === 'some-alias' && | ||
$request['message'] === '"some-message"'; | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.