Freek Van der Herten1 min readintermediate
`exit()` may silently break your parallel tests
Summary
Calling `exit()` inside a test kills the whole PHPUnit worker process, so parallel test runs lose the test result and show no error. Throw an exception instead to let PHPUnit capture the failure and print a stack trace.
- In parallel test execution (e.g., PHPUnit's `--processes`), `exit()` aborts the entire worker process, bypassing PHPUnit's error handling.
- The process termination is silent; verbose flags (`-v`, `--debug`) don’t surface the cause because the test runner never regains control.
- Replace `exit()` with an exception (or let the test fail naturally) so the failure is reported with a stack trace and does not crash other workers.
A single stray `exit()` can make a whole batch of parallel tests appear to pass, hiding real bugs and wasting CI time debugging flaky runs.
5/10


