使用composer安装后找不到PHPunit命令

bod*_*i87 5 php phpunit

我在以下位置添加了 PHPUnit 依赖项composer.json

"require": {
  "php-ds/php-ds": "v1.2.0",
  "phpunit/phpunit": "v7.5.16"
}
Run Code Online (Sandbox Code Playgroud)

并运行我已经php-ds安装的composer update 。

这在供应商目录中安装了 PHPUnit,但是当我检查phpunit命令行时,它说:

找不到phpunit命令

Ger*_*che 12

$ phpunit当您在命令行(例如 bash)上运行时,系统将从bash 文档中查找phpunit使用该变量:PATH

\n\n
PATH   The search path for commands.  It is a colon-separated list of directories in which the shell\n      looks for commands (see COMMAND EXECUTION below).  A zero-length (null) directory name in the\n      value of PATH indicates the current directory.  A null directory name may appear as two adja\xe2\x80\x90\n      cent  colons,  or as an initial or trailing colon.  The default path is system-dependent, and\n      is set by the administrator who installs bash.  A common value is ``/usr/local/bin:\n      /usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\'\'.\n
Run Code Online (Sandbox Code Playgroud)\n\n

您可以使用绕过搜索PATH通过使用绝对路径来绕过使用变量的搜索:

\n\n
$ /absolute/path/to/vendor/bin/phpunit\n
Run Code Online (Sandbox Code Playgroud)\n\n

或相对路径(停止字符(.)表示当前目录):

\n\n
$ ./vendor/bin/phpunit\n
Run Code Online (Sandbox Code Playgroud)\n\n

您实际上省略了停止斜杠部分:$ vendor/bin/phpunit

\n\n

为了避免键入路径,您可以使用 bash 别名(如果您使用的是 bash):

\n\n
$ alias phpunit=\'./vendor/bin/phpunit\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者保存输入:

\n\n
$ alias p=\'./vendor/bin/phpunit\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

请参阅如何创建永久 bash 别名有关别名的更多信息,

\n