5
votes

I am trying to run unit tests in a new laravel 5 application, using the phpunit framework. In the root path of my laravel application I ru the following command:

./vendor/bin/phpunit /tests/ExampleTest.php

And then I get the following message:

You need to set up the project dependencies using the following commands:
wget http://getcomposer.org/composer,phar
php composer.phar install

I already have composer installed in may system and I install Laravel 5 using composer. Isn't phpunit installed when I install a new laravel 5 application? If not, how can I install it in a existent laravel 5 application?

I known that I can also install phpunit globaly and resolve the problem. But maybe it will be a duplication since I have all the phpunit code already in may laravel application.

5
Did you run composer install/composer update? Do you have a vendor directory in your app project?Jeremy D
I have composer installed globally so I already run composer install. Then I run composer update an then it work running the tests. I just wander why phpunit wasn't install in the first time I install the Laravel application. @JeremyD you can transform your comment as a answer to I can accept it as the correct answer.miguelbgouveia
miguelbgouveia done.Jeremy D

5 Answers

11
votes

I had the same problem and it had a specific solution that may apply to other people. I store my files in Dropbox, and the vendor/bin/phpunit file should be an symlink like this

$ ls -lo vendor/bin/phpunit
lrwxr-xr-x   vendor/bin/phpunit -> ../phpunit/phpunit/phpunit

However, Dropbox will occasionally replace symlinks with the original file, and this will cause the error above. The behaviour is inconsistent, and with relative symlinks seems to break when 2 machines are accessing Dropbox at the same time. Fixing the symlink worked for me or you could make a new symlink directly to the vendor/phpunit/phpunit/phpunit outside of Dropbox and run that.

Edit: Nowadays I exclude Vendor and node_modules from Dropbox - and simply run composer install when necessary. This works really well, and also deals with the hassle of syncing so many files on Dropbox. What you can do is go into the folder and delete all the files. Wait for Dropbox to sync. Then mark the folder as excluded. Finally, run composer install and you get the contents as you need. (Delete + composer install often solves other issues too).

3
votes

You need to have Composer installed and run composer install or composer update in your application to install the different packages listed in your composer.json.

When you install your Laravel application it doesn't install the packages right away.

You can verify the packages are installed by looking in the vendor directory of your application and check that phpunit is in there.

1
votes

did you install phpunit globally? I recommend you do it.

just type in your laravel's root directory (e.g. /var/www)

cd /var/www
phpunit

if you what to test just one file, you can do something like this:

phpunit tests/ExampleTest.php
1
votes

Running composer install did nothing in my case. However, removing vendor folder and then calling composer install fixed it.

0
votes

Unit Test:

D:\xampp\htdocs\Samplemed\vendor\bin>

phpunit ../../tests/Unit/Company/CompanyUnitTest

Feature Test:

D:\xampp\htdocs\Samplemed\vendor\bin>phpunit 

../../tests/Feature/Company/CompanyFeatureTest

Please try this. its working fine.