Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/Runner/ShutdownHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private static function register(): void
return;
}

self::$registered = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStan should have detected this problem: phpstan/phpstan#13384

register_shutdown_function(static function (): void
{
print self::$message;
Expand Down
17 changes: 17 additions & 0 deletions tests/end-to-end/regression/6234.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6234
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/6234/Issue6234Test.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->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.
23 changes: 23 additions & 0 deletions tests/end-to-end/regression/6234/Issue6234Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* 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);
Copy link
Contributor Author

@staabm staabm Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

}
}
Loading