Skip to content
New issue

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

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

Already on GitHub? # to your account

Add result shorthands for Process fakes #52840

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Sep 18, 2024

This adds two new shorthands for faking process results in tests. The first is a shorthand to simply set the exit code. The second is a shorthand to throw an exception.

Process::fake([
    'php -l script.php' => 255, 
    'cat README.txt' => new \RuntimeException('fake exception message'),
]);

Note: while the latter is not common as it is only possible for the underlying Symfony Process to throw a RuntimeException. This path was hard to test unless a fake process can throw an exception - basically you had to single out the command in a callback, then throw. This is cleaner and can be used to test other paths, such as process timeout, etc.

@jasonmccreary jasonmccreary changed the title Add testing shorthands for fakes Add testing shorthands for Process fakes Sep 18, 2024
@jasonmccreary jasonmccreary changed the title Add testing shorthands for Process fakes Add result shorthands for Process fakes Sep 18, 2024
@taylorotwell taylorotwell merged commit f243db7 into laravel:11.x Sep 18, 2024
33 checks passed
@taylorotwell
Copy link
Member

Thanks!

@jasonmccreary jasonmccreary deleted the process-shorthands branch September 18, 2024 17:06
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants