Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running PHPUnit in Laravel's Homestead

I'm using Homestead to serve my Laravel application. I'm trying to run PHPUnit. According to the docs:

An example test file is provided in the app/tests directory. After installing a new Laravel application, simply run phpunit on the command line to run your tests.

Well, when I'm "simply running" phpunit in my project root (inside the Homestead environment) I get this:

The program 'phpunit' is currently not installed.

Do I need to install PHPUnit separately then? The documentation does not mention it. What am I doing wrong?

like image 807
lesssugar Avatar asked Jan 23 '15 16:01

lesssugar


People also ask

How do I run a PHPUnit test?

How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.

What is laravel Homestead?

Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. Vagrant provides a simple, elegant way to manage and provision Virtual Machines.


1 Answers

You can install it globally on the system using.

composer global require phpunit/phpunit

However, if you need different versions for different projects this can cause issues.

The alternative option is to use the version installed as part of your dependencies by referencing the path to your vendor directory.

./vendor/bin/phpunit

You could even add an alias to your aliases file in your ~/Homestead directory. That way you're always using the phpunit version that is installed with your project dependencies.

alias phpunit=./vendor/bin/phpunit

You'll need to restart the homestead box to make use of the alias.

like image 72
Wader Avatar answered Oct 18 '22 20:10

Wader