I\'ve recently installed laravel and have written some tests in /tests directory but when I use phpunit
at cmd in the same folder that phpunit.xml
If you are a window user and you are having this issue, do this:
You need to tell Window where to find PHPUnit command, you can first of all verify that this file exists in your Laravel project under /vendor/bin
Finally you need to append the full path to /vendor/bin
in your window PATH variable,
To do this: 1. Right-click on 'Computer' then click properties
Advanced system settings
Advanced
click Environmental Variables
PATH
then set PATH variable by appendingthe full path to your laravel-project/vendor/bin;
Notice the ;
at the end.
NB: Other variables might already exists in the PATH, so ensure you don't overwrite them by appending your own at the very end
Ok
on all the dialog boxes alias phpunit="vendor/bin/phpunit"
With Laravel phpunit is set up right out of the box. The easiest way to run it on Windows is to add an entry to scripts in your package.json file...
"scripts": {
...
"tests": "php vendor/phpunit/phpunit/phpunit"
},
Now you simply run unit tests with
npm run tests
I added this command in command line instead of just "phpunit"
vendor\bin\phpunit
That worked for me.
Install phpunit
globally:
composer global require phpunit/phpunit
Afterwards you will be able to run phpunit
( even on Windows ):
phpunit
Borrowing from @Chris' excellent answer:
Even better, you can make vendor/phpunit/phpunit/phpunit
an environment variable, say "phpunit" and whenever you want to run the test in any laravel project you just call php %phpunit%
.