PHPUnit "phpunit: command not found" in CI
PHPUnit installed via Composer lives at vendor/bin/phpunit, not on the global PATH. Calling a bare phpunit, or installing with --no-dev so the dev tool is excluded, leaves the shell unable to find the command.
What this error means
A test step fails with "phpunit: command not found" or "vendor/bin/phpunit: No such file or directory". PHPUnit is a dev dependency that was either not installed or not invoked via its vendor path.
$ phpunit
bash: phpunit: command not found
# or
$ vendor/bin/phpunit
bash: vendor/bin/phpunit: No such file or directoryCommon causes
Dev dependencies were not installed
composer install --no-dev (or a missing install) skips require-dev, so PHPUnit’s binstub is never created.
PHPUnit invoked from the wrong path
A bare phpunit relies on a global install that is not present; the Composer-installed binary is at vendor/bin/phpunit.
How to fix it
Install dev dependencies and use the vendor binstub
Run a full install in the test job and call PHPUnit by its vendor path.
composer install --no-interaction --prefer-dist
vendor/bin/phpunitRun it through Composer scripts
Define a test script so the command is consistent across environments.
{
"scripts": {
"test": "phpunit"
}
}
# then in CI: composer testHow to prevent it
- Install dev dependencies (no --no-dev) in test jobs.
- Invoke PHPUnit via vendor/bin/phpunit or a composer test script, never a bare phpunit.
- Reserve --no-dev for the deploy artifact, not the test job.