Skip to content

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
@taylorotwell
Copy link
Member

Thanks!

@jasonmccreary jasonmccreary deleted the process-shorthands branch September 18, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants