Merge branch '3.3' into 3.4

* 3.3:
  Ensure that PHPUnit's error handler is still working in isolated tests
  Fix review points
This commit is contained in:
Nicolas Grekas 2017-10-24 19:17:17 +02:00
commit 03b01c36e4
3 changed files with 25 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

@ -326,6 +326,12 @@ class SymfonyTestsListenerTrait
return $h ? $h($type, $msg, $file, $line, $context) : false;
}
// If the message is serialized we need to extract the message. This occurs when the error is triggered by
// by the isolated test path in \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest().
$parsedMsg = @unserialize($msg);
if (is_array($parsedMsg)) {
$msg = $parsedMsg['deprecation'];
}
if (error_reporting()) {
$msg = 'Unsilenced deprecation: '.$msg;
}

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);
}
}