How to create a Symbolic link to PHPUnit?

南楼画角 提交于 2019-12-24 10:51:51

问题


I'm using Laravel. Whenever I need to run the tests I have to execute PHPUnit in the following directory:

vendor/phpunit/phpunit/phpunit

How can I create a symlink to the file above so that I don't have to type in the full path to phpunit every time ?

I tried the following command but didn't work:

ln -s vendor/phpunit/phpunit/phpunit mysym 

For some reason, it says 'Command Not Found' when I try to execute the Symlink.


回答1:


How can I create a symlink to the file above so that I don't have to type in the full path to phpunit every time ?

You don't do any symlinks. Instead you need to add that path to your $PATH variable. Additionally, you should use vendor/bin folder, not the package's folders directly.

So in your shell do:

$ export PATH=$PATH:/home/you/project/vendor/bin/

You can add that to your .bashrc as well.




回答2:


composer.json has an option to set where command files are placed:

"bin-dir": "vendor/bin",

It can be set to just "bin" - and so it, and the other runnable files that are included by Composer would be there, for example bin/phpunit.

See: https://getcomposer.org/doc/articles/vendor-binaries.md

There is also another option available - the composer scripts, which is also used to run the "post-install-cmd" & "post-update-cmd", but you can put your own command in there.

"scripts": {
    "test": "phpunit -v --debug",
    "behat": "behat",
    "post-install-cmd": [
    ... rest of composer.json

Here, if I type composer test, it will run PHPunit with the command line given.



来源:https://stackoverflow.com/questions/46837745/how-to-create-a-symbolic-link-to-phpunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!