Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PhpUnitBridge] Fix DeprecationErrorHandler with PhpUnit 10 #54797

Merged

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented May 1, 2024

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.:

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.:

  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.

@nicolas-grekas
Copy link
Member

Thank you @HypeMC.

@nicolas-grekas nicolas-grekas merged commit e86406f into symfony:5.4 May 16, 2024
4 of 13 checks passed
@HypeMC HypeMC deleted the fix-deprecation-handler-with-phpunit10 branch May 16, 2024 14:53
@fabpot fabpot mentioned this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants