Problem/Motivation

PHPUnit 12.5.0 started throwing notices when mocks do not configure expectations, e.g.

* No expectations were configured for the mock object for \Drupal\comment\CommentManagerInterface. You should refactor your test code and use a test stub instead.

Also, the $this->any() expectation is deprecated - a change that will be released in version 12.5.5. This is because the any() expectation is equivalent to having no expectation. Instances of expects($this->any()) should be removed, either by deletion or conversion to a more specific number of expectations.

Steps to reproduce

  1. Require PHPUnit 12 with Composer.
  2. Fix compatibility issues with PHPUnit 12 by applying this patch.
  3. Run the Unit tests for a module with --display-phpunit-notices.
  4. Observe the PHPUnit notices that occur.

Proposed resolution

Fix notices in the user module.

Remaining tasks

Information on how to review these issues and the types of changes you're likely to find in them is included in the parent issue's comments.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3569423

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

dcam created an issue. See original summary.

dcam’s picture

Status: Active » Needs review
dcam’s picture

Issue summary: View changes
smustgrave’s picture

Confirmed all instances of any() were replaced/removed

Reviewed the 35 instances of createMock() to verify the ones that remain and they appear to be calling specific methods so appear valid.

Reviewed your comments, think we should open a follow up to rethink that test. Mind opening that real quick?

dcam’s picture

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

longwave’s picture

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

Thanks for picking these up. This one is trickier to review and there are indeed some cases that are harder to call. I think it was right to open the followup and there's a couple more spots that could perhaps be stubs as we shouldn't be testing the functionality at all, but ultimately it doesn't really matter too much.

Committed and pushed ea54ea1f989 to main and fd135900c7d to 11.x. Thanks!

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 fd135900 on 11.x
    test: #3569423 Convert expectation-less test mocks to stubs - User...

  • longwave committed ea54ea1f on main
    test: #3569423 Convert expectation-less test mocks to stubs - User...

Status: Fixed » Closed (fixed)

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