From 5333680f7d14645161000a7b6796475807e42930 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 18 Oct 2017 12:32:05 +0100 Subject: [PATCH 1/2] Fix review points --- .../Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index 532ce202af..6a0d9aec99 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -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; } From dc7e5a39fa66283d20b6db6dcb55f8d3274f81a2 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 16 Oct 2017 14:30:39 +0100 Subject: [PATCH 2/2] Ensure that PHPUnit's error handler is still working in isolated tests --- .../Bridge/PhpUnit/DeprecationErrorHandler.php | 6 ++++++ .../Bridge/PhpUnit/Tests/ProcessIsolationTest.php | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 011c28e948..9397af1f22 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -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)); }); diff --git a/src/Symfony/Bridge/PhpUnit/Tests/ProcessIsolationTest.php b/src/Symfony/Bridge/PhpUnit/Tests/ProcessIsolationTest.php index 0cfbe515ee..ec8f124a5f 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/ProcessIsolationTest.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/ProcessIsolationTest.php @@ -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); + } }