8000 bug #54797 [PhpUnitBridge] Fix `DeprecationErrorHandler` with PhpUnit… · symfony/symfony@e86406f · GitHub
[go: up one dir, main page]

Skip to content

Commit e86406f

Browse files
bug #54797 [PhpUnitBridge] Fix DeprecationErrorHandler with PhpUnit 10 (HypeMC)
This PR was merged into the 5.4 branch. Discussion ---------- [PhpUnitBridge] Fix `DeprecationErrorHandler` with PhpUnit 10 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Currently, when using the `DeprecationErrorHandler` with PhpUnit 10, warnings are ignored, e.g.: ```php use PHPUnit\Framework\TestCase; class ExampleTest extends TestCase { public function testFindUniqueTournamentMonths(): void { $someVar = $nonExistentVar; // $nonExistentVar doesn't exist self::assertSame(1, 1); } } ``` ``` PHPUnit 10.5.20 by Sebastian Bergmann and contributors. Runtime: PHP 8.3.4 Configuration: /app/phpunit.xml.dist PHP Warning: Undefined variable $nonExistentVar in /app/tests/ExampleTest.php on line 11 Warning: Undefined variable $nonExistentVar in /app/tests/ExampleTest.php on line 11 . 1 / 1 (100%) Time: 00:00.010, Memory: 19.22 MB OK (1 test, 1 assertion) ``` The reason I added the closure was to return `true`, otherwise, the errors would still be displayed, e.g.: ```diff if ('PHPUnit\Util\ErrorHandler::handleError' === $eh) { return $eh; + } elseif (ErrorHandler::class === $eh) { + return ErrorHandler::instance(); } ``` ``` PHPUnit 10.5.20 by Sebastian Bergmann and contributors. Runtime: PHP 8.3.4 Configuration: /app/phpunit.xml.dist PHP Warning: Undefined variable $nonExistentVar in /app/tests/ExampleTest.php on line 11 Warning: Undefined variable $nonExistentVar in /app/tests/ExampleTest.php on line 11 W 1 / 1 (100%) Time: 00:00.009, Memory: 19.22 MB OK, but there were issues! Tests: 1, Assertions: 1, Warnings: 1. ``` Now, it works as expected: ``` PHPUnit 10.5.20 by Sebastian Bergmann and contributors. Runtime: PHP 8.3.4 Configuration: /app/phpunit.xml.dist W 1 / 1 (100%) Time: 00:00.008, Memory: 19.22 MB OK, but there were issues! Tests: 1, Assertions: 1, Warnings: 1. ``` Commits ------- ca9f2a5 [PhpUnitBridge] Fix `DeprecationErrorHandler` with PhpUnit 10
2 parents f68a8df + ca9f2a5 commit e86406f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ private static function getPhpUnitErrorHandler()
368368

369369
if ('PHPUnit\Util\ErrorHandler::handleError' === $eh) {
370370
return $eh;
371+
} elseif (ErrorHandler::class === $eh) {
372+
return function (int $errorNumber, string $errorString, string $errorFile, int $errorLine) {
373+
ErrorHandler::instance()($errorNumber, $errorString, $errorFile, $errorLine);
374+
375+
return true;
376+
};
371377
}
372378

373379
foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {

0 commit comments

Comments
 (0)
0