Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run phpunit tests from command line

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.

like image 354
miguelbgouveia Avatar asked Jun 01 '15 16:06

miguelbgouveia


1 Answers

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

like image 165
Gazzer Avatar answered Nov 10 '22 00:11

Gazzer