Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpunit command doesn't work for laravel 4 on windows 7

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 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?

like image 285
Ramin Omrani Avatar asked Jun 21 '14 19:06

Ramin Omrani


9 Answers

The solution for me:

php vendor/phpunit/phpunit/phpunit

This, of course, assumes you've set up a php environment variable in Windows

like image 114
Chris Avatar answered Oct 21 '22 15:10

Chris


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.

like image 38
Michael A Avatar answered Oct 21 '22 14:10

Michael A


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

enter image description here

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

enter image description here

  1. On the second window click Advanced system settings

enter image description here

  1. On the next window under Advanced click Environmental Variables

enter image description here

  1. 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

  1. Finally click Ok on all the dialog boxes

enter image description here

like image 41
Emeka Mbah Avatar answered Oct 21 '22 15:10

Emeka Mbah


alias phpunit="vendor/bin/phpunit"
like image 36
RektByAyyLMAO Avatar answered Oct 21 '22 13:10

RektByAyyLMAO


I added this command in command line instead of just "phpunit"

vendor\bin\phpunit

That worked for me.

like image 26
vimuth Avatar answered Oct 21 '22 15:10

vimuth


Install phpunit globally:

composer global require phpunit/phpunit

Afterwards you will be able to run phpunit ( even on Windows ):

phpunit
like image 35
Iter Ator Avatar answered Oct 21 '22 15:10

Iter Ator


The phpunit executable is not in your project root folder, that's why it can't find it.

Now I assume that you already have phpunit in your composer.json file, something like this:

"require-dev": {
    "phpunit/phpunit": "3.7.*"
}

When installed by composer, the package will be installed to vendor/vendor_name/package_name. So to run it at your project root, type this command:

vendor/phpunit/phpunit/phpunit
like image 21
Unnawut Avatar answered Oct 21 '22 14:10

Unnawut


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%.

Demonstration

enter image description here enter image description here

like image 21
Tobi Alafin Avatar answered Oct 21 '22 15:10

Tobi Alafin


This working for me

In double quotes this command in console windows

"vendor/bin/phpunit"

like image 45
Gustavo Marquez Avatar answered Oct 21 '22 14:10

Gustavo Marquez