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 following modules that have small numbers of changes:

  • block_content
  • editor
  • file
  • help
  • image
  • media
  • path_alias
  • rest
  • search
  • update

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-3569429

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
dcam’s picture

Issue summary: View changes

I reverted the changes to the contact module since it has been split off to contrib.

dcam changed the visibility of the branch 3569429-stub-conversion to hidden.

dcam changed the visibility of the branch 3569429-stub-conversion to active.

smustgrave’s picture

Status: Needs review » Needs work

Per the other ones seems a new deprecation came out. Not sure if you want to wait for the phpstan issues to land first?

dcam’s picture

Status: Needs work » Needs review

The modules being handled in this issue are not affected by the new deprecation in PHPUnit 12.5.11. So I'm setting the status back to Needs Review.

@smustgrave and I discussed waiting on the PHPStan issue in Slack. For the benefit of anyone else reading this: whether PHPStan is changed or not doesn't affect the relevance of these changes. The PHPStan change is meant to prevent new instances of any() from being introduced by new commits.

smustgrave’s picture

dcam’s picture

FYI: the recently-committed UnitTestCase changes have been merged into this MR, so they do not need to be applied separately.

smustgrave’s picture

Title: Convert expectation-less test mocks to stubs - batch 3 » Convert expectation-less test mocks to stubs - block_content, editor, file, help, image, media, path_alias, rest, search, update
Status: Needs review » Reviewed & tested by the community

block_content = OK (2 tests, 2 assertions)
editor = OK (195 tests, 205 assertions)
file = OK (39 tests, 44 assertions)
help = OK (14 tests, 34 assertions)
image = OK (4 tests, 25 assertions)
media = OK (27 tests, 45 assertions)
path_alias = OK (13 tests, 81 assertions)
rest = OK (53 tests, 324 assertions)
search = OK (10 tests, 67 assertions)
update = OK (53 tests, 326 assertions)

Know search is marked to be deprecated but think that's still in preliminary steps.

  • catch committed 0b04e144 on main
    task: #3569429 Convert expectation-less test mocks to stubs -...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to main, 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.

Status: Fixed » Closed (fixed)

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