Home » Php » Laravel 4 testing; 'phpunit' is not recognized?

Laravel 4 testing; 'phpunit' is not recognized?

Posted by: admin November 29, 2017 Leave a comment


http://four.laravel.com/docs/testing Says “After installing a new Laravel application, simply run phpunit on the command line to run your tests.”

phpunit isn’t recognized, I also tried php artisian test and php artisan phpunit

Is phpunit in some weird folder, or is it actually not included with Laravel? I don’t want to install it and have two if it is.


Install with composer

An easy way to get up and running with PHPUnit (without needing to install Pear and clutter up every system you want to use this on) is to include it in your composer.json file, like

"phpunit/phpunit": "4.0.*",

Then after doing a composer update you’ll be able to run PHPUnit from command line like this:


Since phpunit will be installed into the vendor/bin folder.

This will install PHPUnit to this project only, not your whole system. So when you want it gone, you simply remove the line from your composer.json file, run composer update, and poof, not a trace.

Installing for development environments only

If you only want to use this during development, add the composer line inside the “require-dev” section. That way it will only be installed when you opt to install dev dependancies via:

php composer.phar install --dev


php composer.phar update


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


The easiest way to use phpunit is to put phpunit.phar in the root of your application and to run it with php phpunit.phar.


If you run into “phpunit requires ext-dom” it’s because php-xml isn’t installed.


You need to install phpunit and the best way is with pear.

pear channel-discover pear.phpunit.de
pear install phpunit/PHPUnit

If you don’t have pear installed, check this regarding pear installation.