Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit - How to add vendor/bin into path?

I installed PHPUnit with composer. Everytime I run it, I have to call vendor/bin/phpunit. How can I put vendor/bin into path, so that next time I only need to call phpunit to run it?

like image 810
user1995781 Avatar asked Nov 05 '14 09:11

user1995781


3 Answers

You could add the current directory into your path.

For Linux/Mac add the following into your .bash_profile, Windows would be similar, alter the line below and add it into your PATH.

# include the current `vendor/bin` folder (Notice the `.` - This means current directory)
PATH="./vendor/bin:$PATH"

Remember to restart your terminal or resource your bash_profile.

Now you should be able to run: phpunit and it will automatically look for it within ./vendor/bin and if it exists it will execute using that.

like image 101
Anil Avatar answered Nov 20 '22 21:11

Anil


If you are running on Homestead (or some other Linux/Ubuntu system):

alias p='vendor/bin/phpunit'

Then you can just type p and it will run your tests

If you are using Homestead - you can add this alias to your aliases file so it is always there.

like image 5
Laurence Avatar answered Nov 20 '22 20:11

Laurence


Another easy solution, from the composer documentation, is to set your bin-dir setting to ./. This will install the binary in your root directory.

"config": {
    "bin-dir": "./"
}

Then you can just run ./phpunit. I typically set bin-dir to bin, then type bin/phpunit. It's short enough for me.

If you already have phpunit installed, you will need to delete the vendor/phpunit directory and rerun composer install before composer will move the binary.

like image 4
Justin Howard Avatar answered Nov 20 '22 20:11

Justin Howard