Skip to content
Latchkey

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.

phpunit
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 run

Common 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
composer install --no-interaction
vendor/bin/phpunit

Provide env/config the bootstrap needs

  1. Set any env vars the bootstrap reads (APP_ENV, DB stub) in the CI job.
  2. Use a test bootstrap that avoids real external calls.
  3. Run php tests/bootstrap.php directly to reproduce the fatal in isolation.
php
export APP_ENV=testing
vendor/bin/phpunit

Point phpunit.xml at the right bootstrap

Confirm the bootstrap path is correct and the file uses __DIR__-relative requires.

php
<phpunit bootstrap="vendor/autoload.php"> <!-- or tests/bootstrap.php --></phpunit>

How to prevent it

  • Run composer install before PHPUnit so the autoloader exists.
  • Keep test bootstrap lightweight and free of real external calls.
  • Provide every env var the bootstrap reads in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →