PHPUnit - How to add a / bin provider to a path?

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

+6
source share
3 answers

You can add the current directory to your path.

For Linux / Mac, add the following to your .bash_profile , Windows will look similar, change the line below and add it to your PATH .

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

Remember to reload your terminal or bash_profile resource.

You should now be able to run: phpunit , and it will automatically search for it in ./vendor/bin , and if it exists, it will execute with that.

+8
source

Another simple solution from the composer 's documentation is to set the bin-dir parameter to ./ . This will install the binary to the root directory.

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

Then you can just run ./phpunit . Usually I set bin-dir to bin , then type bin/phpunit . This is short enough for me.

If you already have phpunit installed, you will need to remove the vendor/phpunit and run composer install again before the composer moves the binary.

+2
source

If you work in Homestead (or some other Linux / Ubuntu system):

 alias p='vendor/bin/phpunit' 

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

If you use Homestead, you can add this alias to your aliases file so that it always exists.

0
source

Source: https://habr.com/ru/post/977753/


All Articles