laravel PHPUnit - 如何将供应商/bin 添加到路径中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26753674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPUnit - How to add vendor/bin into path?
提问by user1995781
I installed PHPUnit with composer. Everytime I run it, I have to call vendor/bin/phpunit. How can I put vendor/bininto path, so that next time I only need to call phpunitto run it?
我用作曲家安装了 PHPUnit。每次我运行它时,我都必须调用vendor/bin/phpunit. 我如何vendor/bin放入路径,以便下次我只需要调用phpunit运行它?
回答by Anil
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.
对于 Linux/Mac,将以下内容.bash_profile添加到您的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.
请记住重新启动您的终端或资源您的bash_profile.
Now you should be able to run: phpunitand it will automatically look for it within ./vendor/binand if it exists it will execute using that.
现在您应该能够运行:phpunit它会自动在其中查找它./vendor/bin,如果它存在,它将使用它来执行。
回答by Laurence
If you are running on Homestead (or some other Linux/Ubuntu system):
如果您在 Homestead(或其他一些 Linux/Ubuntu 系统)上运行:
alias p='vendor/bin/phpunit'
Then you can just type pand it will run your tests
然后你只需输入p它就会运行你的测试
If you are using Homestead - you can add this alias to your aliasesfile so it is always there.
如果您正在使用 Homestead - 您可以将此别名添加到您的aliases文件中,以便它始终存在。
回答by Justin Howard
Another easy solution, from the composer documentation, is to set your bin-dirsetting to ./. This will install the binary in your root directory.
另一个来自composer 文档的简单解决方案是将您的bin-dir设置设置为./. 这将在您的根目录中安装二进制文件。
"config": {
"bin-dir": "./"
}
Then you can just run ./phpunit. I typically set bin-dirto bin, then type bin/phpunit. It's short enough for me.
然后你就可以运行了./phpunit。我通常设置bin-dir为bin,然后键入bin/phpunit。对我来说已经够短了。
If you already have phpunit installed, you will need to delete the vendor/phpunitdirectory and rerun composer installbefore composer will move the binary.
如果您已经安装了 phpunit,则需要删除该vendor/phpunit目录并重新运行,composer install然后Composer才会移动二进制文件。

