PHPUnit not working with Laravel 5

I just installed a new Laravel 5 project, my first in this version. It is assumed that PHPUnit is not included with the framework, and in every tutorial I have seen, just type phpunit in the project folder to run Unit Tests.

I checked and PHPUnit is in composer.json , I also did composer install and composer update just in case it won't be here

 website(master)$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) - Removing phpunit/phpunit (4.6.1) - Installing phpunit/phpunit (4.6.2) Downloading: 100% 

But it just does not work phpunit is not recognized at all

  website(master)$ phpunit -bash: phpunit: command not found 

It seems that no one got this problem before I sorted it out. I hope I will not make a stupid mistake. Any idea or suggestion? Thanks guys;)

+13
source share
6 answers

I did not install PHPUnit globally and did not specify the path. Therefore, for those who would have the same problem:

 composer global require phpunit/phpunit composer global require phpunit/dbunit 

Then you add this to yourself ~/.bash_profile or ~/.profile

 export PATH=~/.composer/vendor/bin:$PATH 
+41
source

This happens when you do not have phpunit installed globally.

Run this command to use the local version (installed with the composer):

 vendor/bin/phpunit 
+15
source

in a windows machine the command is different, please use this command

 php vendor/phpunit/phpunit/phpunit 

original source

+5
source

You can run this command in cmd before running the phpunit :

 doskey phpunit="vendor/bin/phpunit" 

And if you are lazy, like me, you can run this:

 doskey pu="vendor/bin/phpunit" 
+1
source

Include this line in your .json composer

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

Run composer update. You should be able to run the following command in your Laravel directory.

 vendor/bin/phpunit 
0
source

for people who have WINDOWS 7, use the command .\vendor\bin\phpunit instead of ./vendor/bin/phpunit

0
source

Source: https://habr.com/ru/post/984823/


All Articles