我用composer安装了PHPUnit。我每次运行它都需要拨打vendor/bin/phpunit
。如何将vendor/bin
放入路径,以便下次我只需要调用phpunit
来运行它?
答案 0 :(得分:11)
您可以将当前目录添加到路径中。
对于Linux / Mac,将以下内容添加到.bash_profile
,Windows将类似,更改下面一行并将其添加到PATH
。
# include the current `vendor/bin` folder (Notice the `.` - This means current directory)
PATH="./vendor/bin:$PATH"
请务必重启您的终端或资源bash_profile
。
现在您应该能够运行:phpunit
并且它会在./vendor/bin
内自动查找它,如果它存在,它将使用它执行。
答案 1 :(得分:3)
来自composer documentation的另一个简单解决方案是将bin-dir
设置为./
。这将在您的根目录中安装二进制文件。
"config": {
"bin-dir": "./"
}
然后你可以运行./phpunit
。我通常会将bin-dir
设置为bin
,然后输入bin/phpunit
。它对我来说足够短。
如果您已安装phpunit,则需要删除vendor/phpunit
目录,然后在composer移动二进制文件之前重新运行composer install
。
答案 2 :(得分:2)
如果您在Homestead(或其他一些Linux / Ubuntu系统)上运行:
alias p='vendor/bin/phpunit'
然后你可以输入p
并运行你的测试
如果您使用的是Homestead - 您可以将此别名添加到aliases
文件中,以便它始终存在。