8000 [PhpUnitBridge] Deprecation bridge for PHPUnit 10.2 by mondrake · Pull Request #50371 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PhpUnitBridge] Deprecation bridge for PHPUnit 10.2 #50371

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

Closed
wants to merge 1 commit into from
Closed

[PhpUnitBridge] Deprecation bridge for PHPUnit 10.2 #50371

wants to merge 1 commit into from

Conversation

mondrake
Copy link
Contributor
@mondrake mondrake commented May 19, 2023
Q A
Branch? 6.4
Bug fix? no
New feature? no
Deprecations? tbd
Tickets Fix #49069
License MIT
Doc PR symfony/symfony-docs#...

This is a first attempt at implementing the deprecation bridge for PHPUnit 10, re #49069. Given the massive changes in PHPUnit internals, the deprecation bridge will have, one way or another, to change accordingly.

So ATM this is more to share my findings to enable a discussion on what the bridge should look like.

The PR is functional, but only partially, and totally untested.

Key points:

  1. Listeners and hooks are gone in PHPUnit 10. In their place, an internal event system is introduced. The error handler also dramatically changed, and now only converts E_* errors into events that are then channeled through the new system, i.e. dispatched to subscribers. So SymfonyTestsListener and DeprecationErrorHandler implementations cannot be just reused. ==> My proposal here is to replace these, for the deprecation bridge, with an event collector and event subscribers.
  2. The test objects have been armoured, it's no longer possible to change their state and make a passed test fail or error. At least, I could not find a way. This means probably that reporting of any fail/errors found by the bridge should be actually deferred to the end of the test run. No more 'E' or 'F' on the PHPUnit cli. ==> For the time being, I made so that where errors or fails should be triggered, we have a dump() instead. But that needs to change. Errors and failures due to the bridge are reported at report-out and no longer as errors/failures in the cli.
  3. PHPUnit's event system does not seem to have a way to allow subscribers to stop event propagation. This means that no matter what the deprecation bridge will capture, PHPUnit itself will perform its own processing and reporting. ATM PHPUnit does not do anything with silenced deprecations (i.e. when the trigger_error() call is prefixed with the @ symbol). But unsilenced deprecations would be reported by both the bridge (according to its configuration) and by PHPUnit itself (unconditionally).
  4. I do not know yet (have not investigated) whether it's possible to influence PHPUnit's cli exit code.
  5. PHPUnit version 10.2 (unreleased yet) is the minimum version for this PR. That's because earlier than that, silenced deprecations were not even processed by the error handler, and that was only fixed in Optionally ignore suppression of deprecations, notices, and warnings sebastianbergmann/phpunit#5328

@carsonbot carsonbot added this to the 6.3 milestone May 19, 2023
@mondrake mondrake changed the title Deprecation bridge for PHPUnit 10.2 [PhpUnitBridge] Deprecation bridge for PHPUnit 10.2 May 19, 2023
@mondrake
Copy link
Contributor Author

Made changes to report error/failures at the report-out time, and advocated exiting early if bridge's status is higher than phpunit's exit code.

@stof
Copy link
Member
stof commented Oct 11, 2023

The deprecations being expected by legacy tests should still be checked during the test run. This should be implemented by having a post condition method (i.e. a protected method with the PostCondition attribute of PHPUnit or the @postCondition tag in phpdoc) in the trait of the bridge that triggers the assertions on the expected deprecations for the current test. this would allow running those assertions before the test status is frozen.
this is the same extension point than used to verify mock objects expectations.

@alexislefebvre
Copy link
Contributor

This PR needs to be rebased, it currently has 152 commits and 3762 files changed.

@rvanlaak
Copy link
Contributor
rvanlaak commented Nov 3, 2023

Right now one can filter the deprecations and get them as grouped output via restrictDeprecations option 👍

@OskarStark this reference to your above ticket on the phpunit repo is really worth mentioning over here! 🙌 Is that feature introduced in PHPUnit for all PHP versions that are supported by the Symfony PhpUnitBridge?

@OskarStark
Copy link
Contributor

Is that feature introduced in PHPUnit for all PHP versions that are supported by the Symfony PhpUnitBridge?

I am not sure and didn't test the feature yes, I just proposed the idea and @sebastianbergmann implemented it

@mondrake
Copy link
Contributor Author
mondrake commented Nov 3, 2023

Is that feature introduced in PHPUnit for all PHP versions that are supported by the Symfony PhpUnitBridge?

It will be part of PHPUnit 10.5 (release due Dec 1 2023), that requires PHP >=8.1. Do not expect backports.

@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@mondrake
Copy link
Contributor Author

For the record, in Drupal we are working on a possible alternative without the bridge, implementing an error handler shim on top of PHPUnit's one, for every test. Sharing in case something there might be reused here.

See https://www.drupal.org/project/drupal/issues/3417066.

@mondrake mondrake closed this Feb 28, 2024
@mondrake mondrake deleted the phpunit10-deprecation-bridge branch May 14, 2024 21:41
@mondrake mondrake restored the phpunit10-deprecation-bridge branch May 14, 2024 21:41
@mondrake mondrake deleted the phpunit10-deprecation-bridge branch July 2, 2024 14:59
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.

[PHPUnit bridge] Support for PHPUnit 11.1+
8 participants
0