PHPUnit: PHP Fatal Error During Bootstrap in CI
PHPUnit runs the configured bootstrap file before any test. If that file (commonly vendor/autoload.php plus test setup) throws a fatal - a missing autoloader, a missing env var, or a failing boot call - the entire suite aborts before a single test executes.
What this error means
PHPUnit dies immediately with a PHP fatal error and no tests run. The error originates in the bootstrap file or something it includes, not in a test, and often references the autoloader or app boot.
PHP Fatal error: Uncaught Error: Failed opening required
'/app/vendor/autoload.php' in /app/tests/bootstrap.php:5
# phpunit.xml: bootstrap="tests/bootstrap.php" -> suite aborts, 0 tests runCommon causes
The autoloader or a required file is missing
Bootstrap requires vendor/autoload.php (or a generated file) that does not exist yet because composer install did not run first.
Bootstrap boots the app and that boot fails
A bootstrap that boots the framework can fatal on a missing env var, DB call, or misconfigured service before tests start.
How to fix it
Install dependencies before running PHPUnit
Ensure the autoloader the bootstrap requires actually exists.
composer install --no-interaction
vendor/bin/phpunitProvide env/config the bootstrap needs
- Set any env vars the bootstrap reads (APP_ENV, DB stub) in the CI job.
- Use a test bootstrap that avoids real external calls.
- Run
php tests/bootstrap.phpdirectly to reproduce the fatal in isolation.
export APP_ENV=testing
vendor/bin/phpunitPoint phpunit.xml at the right bootstrap
Confirm the bootstrap path is correct and the file uses __DIR__-relative requires.
<phpunit bootstrap="vendor/autoload.php"> <!-- or tests/bootstrap.php --></phpunit>How to prevent it
- Run
composer installbefore PHPUnit so the autoloader exists. - Keep test bootstrap lightweight and free of real external calls.
- Provide every env var the bootstrap reads in CI.