简体   繁体   中英

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?

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.

You can install it globally with:

$ composer global require "phpunit/phpunit=4.4.*"
# then use
$ phpunit

or you can use it with your local composer:

$ composer require "phpunit/phpunit=4.4.*"
# then
$ vendor/bin/phpunit

Since it's a package required for development, Laravel provide PHPunit(require-dev section in composer), you should find it in vendor's folder :

$ your_app/vendor/bin/

You can run the command from the root of your app folder by typing :

$ vendor/bin/phpunit

I hope it will help !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM