phpunit command doesn't work for laravel 4 on windows 7
Solution 1
The solution for me:
php vendor/phpunit/phpunit/phpunit
This, of course, assumes you've set up a php environment variable in Windows
Solution 2
As Unnawut said, it doesn't work because vendor/phpunit/phpunit/phpunit is not a native Windows executable. You need a .bat or .cmd file that will basically call 'php phpunit'. There should be one in vendor/bin, but to make life easy, try this - create a file phpunit.bat (or .cmd) at the root of your site, containing this:
@ECHO OFF
SET BIN_TARGET=%~dp0/vendor/phpunit/phpunit/phpunit
php "%BIN_TARGET%" %*
Now you can call phpunit from the command line at the root of the site.
Solution 3
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
- On the second window click
Advanced system settings
- On the next window under
Advanced
clickEnvironmental Variables
- On the next window double-click
PATH
then set PATH variable by appending
the 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
- Finally click
Ok
on all the dialog boxes
Solution 4
alias phpunit="vendor/bin/phpunit"
Solution 5
I added this command in command line instead of just "phpunit"
vendor\bin\phpunit
That worked for me.
Related videos on Youtube
![Ramin Omrani](https://i.stack.imgur.com/aesKS.jpg?s=256&g=1)
Ramin Omrani
I am a software developer based in Rome, Italy, with a particular focus on the web. I became passionate about programming at the age of 14 when I was a member of the Robocup students' team of Tehran. Since then, my passion for learning new tools and trends in programming has never stopped.
Updated on June 14, 2022Comments
-
Ramin Omrani about 2 years
I've recently installed laravel and have written some tests in /tests directory but when I use
phpunit
at cmd in the same folder thatphpunit.xml
exists, it says'phpunit' is not recognized as an internal or external command,operable program or batch file.
. I'm using windows 7. what should I do?-
Ramin Omrani about 10 yearsYes I mean installed it
-
Rahil Wazir about 10 yearsDid you set the environmental variable?
-
Ramin Omrani about 10 yearsEnvironment variables for what?
-
Rahil Wazir about 10 yearsTo be able to run commands with
phpunit
. It was working before? -
Ramin Omrani about 10 yearsno it wasn't , so you mean I should add the phpunit executable to PATH yeah?
-
Rahil Wazir about 10 yearsBig yes! If it isn't already. Try
echo %PATH%
in cmd and see the output containphpunit
-
-
Unnawut about 10 years
composer update
and after that dovendor/phpunit/phpunit/phpunit
from the folder you havephpunit.xml
-
Unnawut about 10 yearsOh well I guess that's as far as I could help. Good luck!
-
Blue almost 8 yearsWhile this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, as this reduces the readability of both the code and the explanations!
-
Sajidur Rahman over 6 yearsThanks for detailed explanation. Solves my problem.
-
Mark Walet over 6 yearsIt wasn't saying that. The error message was something else
-
vimuth about 6 yearsI explained a bit more :)
-
Arno van Oordt over 4 yearsOr you can add
./vendor/bin
to the PATH environment variable. This way you can just callphpunit
from any Laravel root folder. -
Crazy World about 4 years@ArnovanOordtPlease submit your comment as an answer to this question. It easy to implement, is permanent and has global scope. It is the best answer here and deserves it's own post.