Problem/Motivation

When we started using PHPUnit 10, we dropped the dependency to symfony/phpunit-bridge, and added our own custom DeprecationHandler to replace it.

Quite a few parts of the Symfony code were included in the replacement, to allow BC, including the expectDeprecation() method to be used in tests to check deprecations messages are actually triggered.

In the meantime, PHPUnit evolved and in version 11.0, the expectUserDeprecationMessage() and expectUserDeprecationMessageMatches() methods were introduced with basically the same purpose.

https://github.com/sebastianbergmann/phpunit/blob/11.0.10/ChangeLog-11.0...

Proposed resolution

  • Deprecate expectDeprecation (pun moderately intended), and replace its usage with expectUserDeprecationMessage*
  • Deprecate the entire ExpectDeprecationTrait trait
  • Cleanup DeprecationHandler from no longer necessary code

NOTE: differently from expectDeprecation, there is no check in PHPUnit that expectUserDeprecationMessage* are only called within deprecation tests (those marked @group legacy or #[IgnoreDeprecations]). Need to be careful about this.

Remaining tasks

None

Follow ups

See child issues.

Issue fork drupal-3497124

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Issue summary: View changes

mondrake’s picture

mondrake’s picture

Issue tags: +PHPUnit 12
mondrake’s picture

Title: Deprecate expectDeprecation(), use PHPUnit's expectUserDeprecationMessage() instead » [pp-upstream] Deprecate expectDeprecation(), use PHPUnit's expectUserDeprecationMessage() instead
Issue summary: View changes
mondrake’s picture

Title: [pp-upstream] Deprecate expectDeprecation(), use PHPUnit's expectUserDeprecationMessage() instead » Deprecate expectDeprecation(), use PHPUnit's expectUserDeprecationMessage*() instead
Status: Postponed » Active

https://github.com/sebastianbergmann/phpunit/issues/6102 is fixed upstream, so as soon as a release 11.5.33 hits the road this is actionable again

mondrake’s picture

Status: Active » Postponed

With PHPUnit 11.5.34, the facade sealed exception no longer shows, but now we need to complete conversion of all tests to use metadata attributes instead of annotations.

mondrake’s picture

Issue summary: View changes
Related issues: +#3537104: Remove support for PHPUnit 10
mondrake’s picture

Status: Postponed » Needs review

#3537104: Remove support for PHPUnit 10 must happen before committing this, but the MR can be reviewed now.

mondrake’s picture

Issue summary: View changes
mondrake’s picture

mondrake’s picture

Issue tags: -PHPUnit 12
longwave’s picture

If PHPUnit doesn't check IgnoreDeprecations and ours does, and that is important to us, I wonder if this is worth keeping just as a wrapper? Would also save the busy work of making all the changes here and in contrib.

mondrake’s picture

We may not deprecate expectDeprecation(), even if I do not see the benefit of it, longer term. But I think we should definitely remove the collection mechanism at this point, it's a duplicate of PHPUnit's one and already there are are differences between the two, see the draft CR. Developers from outside will get confused if we keep living in our own island.

Re. deprecation ignore file, that remains after this. It's operating on an higher level i.e. before triggered errors are even passed to PHPUnit. In #3558105: [experimental] Remove DeprecationHandler I've started exploring removing it entirely, but it would require upstream changes and we would need to build a strong case for it.

mondrake’s picture

BTW, 99% of the changes will only be renaming expectDeprecation(), to expectUserDeprecationMessage(). That would be low impact if done in a major beta once most deprecated code is removed.

mondrake’s picture

Also, here we would finally get rid of stray #[Group('legacy')] attributes instead of #[IgnoreDeprecations], that are still leaking in. See last commit to MR.

mondrake’s picture

dcam’s picture

I don't feel like I'm the right person to review this, but I gave it my best shot since it's been lingering for a while.

The only thing I noticed was that the deprecation of the entire ExpectDeprecationTrait isn't mentioned in the change record. I feel like it isn't enough to only say that expectDeprecation() is deprecated, if for no other reason than to ensure it pops up in the CR search if someone searches for the trait name.

That's all the feedback I have. Either the MR is pretty solid or I just don't know enough about the test system to judge it.

mondrake’s picture

Issue summary: View changes

Thanks @dcam. I've added your point to the CR and the IS.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Yeah, that looks good. Although the trait is already used by the base classes the fact that several Core tests were using it directly made me think that we needed to mention the deprecation.

Let's see what the committers think.

mondrake’s picture

#21 only the component tests were importing the trait explicitly, which is fine as components should not rely on core code. In the MR I removed all such cases to use directly the now-native methods. #3552827: Replace all expectDeprecation() calls with expectUserDeprecationMessage() will take care of adjusting core tests.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community

rebased

catch’s picture

Status: Reviewed & tested by the community » Needs work

This looks like good clean-up, but there's a typo in the JavaScript deprecation handling and surprised that's not causing test failures here.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
mondrake’s picture

Issue summary: View changes
catch’s picture

Sorry no idea what happened there maybe my monitor had a speck on it or something.

mondrake’s picture

:) I know what you mean, I see commas everywhere

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new5.42 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: +no-needs-review-bot

bot fluke

longwave’s picture

Status: Reviewed & tested by the community » Needs review

Added a question, if there is no overhead (or reasonable workaround) then set this back to RTBC.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Had to think to remember why this.... deprecations triggered during tearDown are no longer captured, so I did not find a better way to check this.

The CR reflects this point:

Deprecations can NO LONGER be triggered in ::tearDown() or methods tagged with the #[After] attribute - due to internal PHPUnit logic that stops collecting deprecations during test finalization.

Happy to hear about alternatives.

longwave’s picture

mondrake’s picture

Assigned: Unassigned » mondrake
Status: Reviewed & tested by the community » Needs work

Let's try, thanks

mondrake’s picture

#35 unfortunately not (would have been a great solution), apparently the deprecation capture has already stopped at that point.

Reverting the last two commits.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC

mondrake’s picture

Assigned: mondrake » Unassigned
mondrake’s picture

Status: Reviewed & tested by the community » Needs review

This latest fix requires setting back to NR. It's becoming more difficult to fix, as deprecation handling under native PHPUnit is diverging from our implementation... IMHO a sign that it's time to get this in and we adopt standard.

smustgrave’s picture

Are all instances of expectDeprecation() suppose to be replaced?

mondrake’s picture

Yes, in a follow up. See #22.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#3572325: Remove non-W3C compliant browser tests

The fix that was necessary for WebDriverTestBaseTest is no longer needed as that test was removed by #3572325: Remove non-W3C compliant browser tests.

This sets back the MR to a stage when it was RTBC, so I'll self-RTBC this.

mondrake’s picture

Needed another reroll for misusage of #[Group('legacy')], in DefaultHtmlRouteProviderTest this time.

  • catch committed 738eeb57 on 11.x
    task: #3497124 Deprecate expectDeprecation(), use PHPUnit's...

  • catch committed 6c78db89 on main
    task: #3497124 Deprecate expectDeprecation(), use PHPUnit's...
catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and 11.x, thanks! Made some very minor edits to the CR which I've also published.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed 873fe896 on 11.x
    test: #3497124 followup to fix WebDriverTestBaseTest.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.