Skip to content
Latchkey

PHPUnit "Cannot open bootstrap script" in CI

PHPUnit loads a bootstrap file (usually vendor/autoload.php) before running tests. When that file does not exist in CI - typically because composer install was skipped or run with the wrong working directory - PHPUnit cannot start.

What this error means

PHPUnit aborts before any test with "Cannot open bootstrap script \"vendor/autoload.php\"" or a similar path. The bootstrap configured in phpunit.xml is not present on disk.

composer
PHPUnit 10.5.0 by Sebastian Bergmann and contributors.

Cannot open bootstrap script "vendor/autoload.php".

Diagnose it: version, extensions, limits

Terminal
php -v && php -m | head -30
php -i | grep -E "memory_limit|max_execution_time"
composer check-platform-reqs 2>/dev/null

Common causes

Dependencies were never installed

composer install did not run (or failed), so vendor/autoload.php was never generated and the bootstrap path is missing.

Wrong working directory or bootstrap path

PHPUnit runs from a directory where the relative bootstrap path does not resolve, or phpunit.xml points at the wrong file.

How to fix it

Install dependencies before running tests

Generate the autoloader so the bootstrap exists.

Terminal
composer install --no-interaction --prefer-dist
vendor/bin/phpunit

Fix the bootstrap path and working directory

  1. Confirm phpunit.xml bootstrap points at the real autoloader (e.g. vendor/autoload.php).
  2. Run PHPUnit from the project root so the relative path resolves.
  3. Re-run the suite.

How to prevent it

  • Always run composer install before PHPUnit in CI.
  • Keep the phpunit.xml bootstrap path correct relative to the project root.
  • Run PHPUnit from the repository root in CI steps.

Frequently asked questions

What causes PHPUnit "Cannot open bootstrap script" in CI?
There are 2 common causes: dependencies were never installed and wrong working directory or bootstrap path. composer install did not run (or failed), so vendor/autoload.php was never generated and the bootstrap path is missing.
How do I fix PHPUnit "Cannot open bootstrap script" in CI?
There are 2 fixes depending on which cause you have: install dependencies before running tests and fix the bootstrap path and working directory. Work through them in order, since the first is the most common.
What does PHPUnit "Cannot open bootstrap script" in CI actually mean?
PHPUnit aborts before any test with "Cannot open bootstrap script \"vendor/autoload.php\"" or a similar path.
How do I stop PHPUnit "Cannot open bootstrap script" in CI happening again?
Always run composer install before PHPUnit in CI. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card