Detect premature end of PHPUnit's main PHP process#6319
Detect premature end of PHPUnit's main PHP process#6319sebastianbergmann merged 4 commits intosebastianbergmann:12.3from
Conversation
| if (!$this->shouldRunInSeparateProcess() || $this->requirementsNotSatisfied()) { | ||
| (new TestRunner)->run($this); | ||
| try { | ||
| ShutdownHandler::setMessage('Fatal error: Premature end of PHP process.'); |
There was a problem hiding this comment.
not sure whether the error is precise enough?
There was a problem hiding this comment.
hmm maybe even PHPUnit process instead of PHP process?
the test itself might not call exit() directly but it might be called from code down the line
| return; | ||
| } | ||
|
|
||
| self::$registered = true; |
There was a problem hiding this comment.
fixes failling end-to-end test:
https://github.com/sebastianbergmann/phpunit/actions/runs/16960222681/job/48071048701?pr=6319
There was a problem hiding this comment.
PHPStan should have detected this problem: phpstan/phpstan#13384
| $this->assertTrue(true); | ||
| $this->assertTrue(true); | ||
|
|
||
| exit(1); |
There was a problem hiding this comment.
just realized there is a even more critical case, namely a test calling exit(0), from non-isolated tests.
this would make PHPUnit return a 0 exit-code and noone would notice (besides the newly added error message), that tests did not run successfully.
stuff for a separate issue though. maybe even stuff for phpstan-phpunit as I can't think of how we can make phpunit return a non-zero exit code, when a test itself calls already exit(0).
when a test calls
exit()phpunit main process halted and printed nothing.since PHPUnit 12.3 we have a
ShutdownHandlerwhich we utilize with this PR to handle this situation and print a more usefull error message.before this PR:
after this PR:
similar to #6234
-> in a separate PR I will add expectation handling for subprocesses.