PHPUnit "Fatal error" during a test run in CI
A PHP fatal error (uncaught Error, type error, missing class) raised while a test executes can crash the PHPUnit process itself, so the run aborts mid-suite instead of recording a single failed test. The fatal in the bootstrap or app code is the real problem.
What this error means
PHPUnit stops partway with "PHP Fatal error: ..." and an incomplete summary, sometimes leaving the suite without a clean pass/fail. The fatal points at app or test code, not an assertion.
PHPUnit 10.5.0 by Sebastian Bergmann and contributors.
..PHP Fatal error: Uncaught TypeError: App\Money::__construct():
Argument #1 ($amount) must be of type int, string given, called in
/app/tests/MoneyTest.php on line 19Common causes
An uncaught fatal in app or test code
A TypeError, undefined method, or missing class throws a fatal during a test, crashing the PHP process running PHPUnit.
A broken bootstrap or fixture
The PHPUnit bootstrap file or a fixture errors out, taking the whole run down before tests can be isolated.
How to fix it
Reproduce and read the fatal
- Run PHPUnit with full error display and a single failing test to isolate the fatal.
- Fix the underlying TypeError/missing class/method in app or test code.
- Re-run the full suite.
Run with verbose error reporting
Surface the exact fatal location so it is not hidden by the crash.
php -d display_errors=1 -d error_reporting=E_ALL \
vendor/bin/phpunit --filter MoneyTestHow to prevent it
- Keep strict types and signatures consistent so TypeErrors surface in development.
- Validate the PHPUnit bootstrap and fixtures so a broken setup does not crash the suite.
- Run the suite locally before pushing to catch fatals early.