Can't run phpunit tests from command line

I am trying to run unit tests in a new laravel 5 application using framing. In the root path of my laravel app, run 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 on the can system and I am installing Laravel 5 using composer. Isn't phpunit installed when I install a new laravel 5 app? If not, how can I install it in an existing laravel 5 application?

I knew I could install phpunit globaly as well and solve the problem. But maybe it will be duplication since I have all phpunit code already in laravel app.

+3


source to share


4 answers


You need to install Composer and run composer install

or composer update

in your application to install the various packages listed in your composer.json

.

When you install a Laravel app, it doesn't immediately install packages.



You can verify that the packages are installed by looking in your application's vendor directory and checking what is there phpunit

.

+3


source


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

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

      



However, Dropbox sometimes replaces symbolic links to the original file , resulting in the above error. The behavior is inconsistent, and with relative symlinks, it seems to break when 2 machines access Dropbox at the same time. Fixing the symlink worked for me, or you can create a new symlink directly vendor/phpunit/phpunit/phpunit

outside of Dropbox and run it.

Edit: I am currently excluding Vendor and node_modules from Dropbox - and just run composer install

as needed. It works really well and also deals with syncing a lot of files in Dropbox. What you can do is go to the folder and delete all files. Wait for Dropbox to sync. Then mark the folder as excluded. Finally, run composer install

and you will get the content as needed. (Delete + composer install

often solves other problems as well).

+9


source


Have you installed phpunit globally? I recommend that you do this.

just enter your laravel root directory (e.g. / var / www)

cd /var/www
phpunit

      

If you only need to check one file, you can do something like this:

phpunit tests/ExampleTest.php

      

+1


source


Unit test:

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

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

      

Functional test:

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

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

      

Please try this. works fine.

0


source







All Articles