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

This commit is contained in:
Alex Pott 2017-10-16 14:30:39 +01:00 committed by Nicolas Grekas
parent 4365d23e38
commit dc7e5a39fa
2 changed files with 19 additions and 0 deletions

View File

@ -255,6 +255,12 @@ class DeprecationErrorHandler
}
$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));
});

View File

@ -21,4 +21,17 @@ class ProcessIsolationTest extends TestCase
@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);
}
}