Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPunit command not found after installing using composer

Tags:

php

phpunit

I have added the PHPUnit dependency in the composer.json:

"require": {
  "php-ds/php-ds": "v1.2.0",
  "phpunit/phpunit": "v7.5.16"
}

and ran composer update as I have php-ds installed already.

This installed the PHPUnit in the vendor directory, but when I check phpunit in command line it says:

phpunit command not found

like image 342
bodi87 Avatar asked Sep 29 '19 23:09

bodi87


1 Answers

When you run $ phpunit on the command-line (e.g. bash), the system will look for phpunit using the PATH variable, from the bash docs:

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

You can bypass search using the PATH variable by using an absolute path:

$ /absolute/path/to/vendor/bin/phpunit

Or a relative path (the stop character (.) means the current directory):

$ ./vendor/bin/phpunit

You actually omit the stop slash part: $ vendor/bin/phpunit.

To avoid having to type the path you can use a bash alias (if you're using bash):

$ alias phpunit='./vendor/bin/phpunit'

Or to save typing:

$ alias p='./vendor/bin/phpunit'

See How do I create a permanent bash alias for more information on aliases.

like image 106
Gerard Roche Avatar answered Dec 07 '22 23:12

Gerard Roche