Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8984260

Browse filesBrowse files
bug #24575 Ensure that PHPUnit's error handler is still working in isolated tests (alexpott)
This PR was squashed before being merged into the 3.3 branch (closes #24575). Discussion ---------- Ensure that PHPUnit's error handler is still working in isolated tests | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the 3.4, legacy code removals go to the master branch. - Please fill in this template according to the PR you're about to submit. - Replace this comment by a description of what your PR is solving. --> This PR fixes the \Symfony\Bridge\PhpUnit\Tests\ProcessIsolationTest and adds new coverage to ensure PHPUnit error handling works as expected. Tested with both PHPUnit 4.8.35 and 6.2.4 Commits ------- dc7e5a3 Ensure that PHPUnit's error handler is still working in isolated tests
2 parents 4365d23 + dc7e5a3 commit 8984260
Copy full SHA for 8984260

File tree

2 files changed

+19
-0
lines changed
Filter options

2 files changed

+19
-0
lines changed

‎src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
+6Lines 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/Tests/ProcessIsolationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/Tests/ProcessIsolationTest.php
+13Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.