Skip to content

Ensure that PHPUnit's error handler is still working in isolated tests #24575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
6 changes: 6 additions & 0 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ public static function collectDeprecations($outputFile)
}
$deprecations[] = array(error_reporting(), $msg);
});
// This can be registered before the PHPUnit error handler.
if (!$previousErrorHandler) {
$UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\';
$previousErrorHandler = $UtilPrefix.'ErrorHandler::handleError';
}

register_shutdown_function(function () use ($outputFile, &$deprecations) {
file_put_contents($outputFile, serialize($deprecations));
});
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Tests/ProcessIsolationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ public function testIsolation()
@trigger_error('Test abc', E_USER_DEPRECATED);
$this->addToAssertionCount(1);
}

public function testCallingOtherErrorHandler()
{
$class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception';
if (method_exists($this, 'expectException')) {
$this->expectException($class);
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
} else {
$this->setExpectedException($class, 'Test that PHPUnit\'s error handler fires.');
}

trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING);
}
}