In my Laravel project, I want to run phpunit for a single file, like this one:
$ composer run-script test tests/Unit/Services/OrderServiceTest.php
Here is my composer setup:
"scripts": {
"test": [
"@testenv",
"@phpunit"
],
"testenv": [
"php artisan config:cache --env=testing",
"php artisan config:clear"
],
"phpunit": [
"php ./vendor/phpunit/phpunit/phpunit --"
]
}
However, I'm running into this error:
www@287dd7480e22:/var/www$ composer run-script test tests/Unit/Services/OrderServiceTest.php
php artisan config:cache --env=testing 'tests/Unit/Services/OrderServiceTest.php'
Too many arguments, expected arguments "command".
Notice:
--
at the end of custom composer script) does not work for my case or I do not understand it properly.There is a trick that allows you to ignore an argument for a sub-script:
"scripts": {
"testenv": [
"php artisan config:cache --env=testing || exit $?",
...
],
...
}
What happens here is that your argument (let's say OrderServiceTest.php
) is appended to the whole command line, but the shell command exit
ignores any further arguments after the exit code. And for the exit code we set $?
which is the exit code of the last running command in order to not change the overall outcome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With