Skip to content

Commit 03b01c3

Browse files
Merge branch '3.3' into 3.4
* 3.3: Ensure that PHPUnit's error handler is still working in isolated tests Fix review points
2 parents b743923 + e6d949b commit 03b01c3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ public static function collectDeprecations($outputFile)
255255
}
256256
$deprecations[] = array(error_reporting(), $msg);
257257
});
258+
// This can be registered before the PHPUnit error handler.
259+
if (!$previousErrorHandler) {
260+
$UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\';
261+
$previousErrorHandler = $UtilPrefix.'ErrorHandler::handleError';
262+
}
263+
258264
register_shutdown_function(function () use ($outputFile, &$deprecations) {
259265
file_put_contents($outputFile, serialize($deprecations));
260266
});

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ public function handleError($type, $msg, $file, $line, $context = array())
326326

327327
return $h ? $h($type, $msg, $file, $line, $context) : false;
328328
}
329+
// If the message is serialized we need to extract the message. This occurs when the error is triggered by
330+
// by the isolated test path in \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest().
331+
$parsedMsg = @unserialize($msg);
332+
if (is_array($parsedMsg)) {
333+
$msg = $parsedMsg['deprecation'];
334+
}
329335
if (error_reporting()) {
330336
$msg = 'Unsilenced deprecation: '.$msg;
331337
}

src/Symfony/Bridge/PhpUnit/Tests/ProcessIsolationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ public function testIsolation()
2121
@trigger_error('Test abc', E_USER_DEPRECATED);
2222
$this->addToAssertionCount(1);
2323
}
24+
25+
public function testCallingOtherErrorHandler()
26+
{
27+
$class = class_exists('PHPUnit\Framework\Exception') ? 'PHPUnit\Framework\Exception' : 'PHPUnit_Framework_Exception';
28+
if (method_exists($this, 'expectException')) {
29+
$this->expectException($class);
30+
$this->expectExceptionMessage('Test that PHPUnit\'s error handler fires.');
31+
} else {
32+
$this->setExpectedException($class, 'Test that PHPUnit\'s error handler fires.');
33+
}
34+
35+
trigger_error('Test that PHPUnit\'s error handler fires.', E_USER_WARNING);
36+
}
2437
}

0 commit comments

Comments
 (0)