diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 3064be86e8..e1c20e7a53 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -352,7 +352,12 @@ final public function run(): void } if (!$this->shouldRunInSeparateProcess() || $this->requirementsNotSatisfied()) { - (new TestRunner)->run($this); + try { + ShutdownHandler::setMessage(sprintf('Fatal error: Premature end of PHP process when running %s.', $this->toString())); + (new TestRunner)->run($this); + } finally { + ShutdownHandler::resetMessage(); + } return; } diff --git a/src/Runner/ShutdownHandler.php b/src/Runner/ShutdownHandler.php index c20aac401d..f060c4dd50 100644 --- a/src/Runner/ShutdownHandler.php +++ b/src/Runner/ShutdownHandler.php @@ -39,6 +39,7 @@ private static function register(): void return; } + self::$registered = true; register_shutdown_function(static function (): void { print self::$message; diff --git a/tests/end-to-end/regression/6234.phpt b/tests/end-to-end/regression/6234.phpt new file mode 100644 index 0000000000..ede356b99f --- /dev/null +++ b/tests/end-to-end/regression/6234.phpt @@ -0,0 +1,17 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/6234 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +Fatal error: Premature end of PHP process when running PHPUnit\TestFixture\Issue6234Test::testExitWithoutProcessIsolation. diff --git a/tests/end-to-end/regression/6234/Issue6234Test.php b/tests/end-to-end/regression/6234/Issue6234Test.php new file mode 100644 index 0000000000..e21794cbc3 --- /dev/null +++ b/tests/end-to-end/regression/6234/Issue6234Test.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture; + +use PHPUnit\Framework\TestCase; + +final class Issue6234Test extends TestCase +{ + public function testExitWithoutProcessIsolation(): void + { + $this->assertTrue(true); + $this->assertTrue(true); + + exit(1); + } +}