Problem/Motivation

PHPUnit 12.5.0+ is changing the way that mock objects work:

  • Mock objects that do not configure expectations should be converted to stubs. Otherwise, they throw a notice: No expectations were configured for the mock object for \Drupal\comment\CommentManagerInterface. You should refactor your test code and use a test stub instead.
  • $this->any() is deprecated. It was equivalent to having no expectation, in which case the object should be a stub (see the previous bullet) or a more exact number of expectations should be added.
  • with() is deprecated for stubs because it was deemed to be equally pointless.

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 --display-phpunit-deprecations.
  4. Observe the PHPUnit notices that occur.

Proposed resolution

Fix notices in the Link 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-3566476

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

Deprecation of any() will be in 12.5.5, afaics. Matter of days.

https://github.com/sebastianbergmann/phpunit/commit/7896ec254eed5e944f4e...

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Looks good and nice cleanup.

dcam’s picture

Status: Reviewed & tested by the community » Needs review
Parent issue: » #3561671: [meta] Refactor tests to use stubs instead of mocks where mocks do not configure expectations
dcam’s picture

Title: Refactor tests to use stubs instead of mocks where mocks do not configure expectations - in Link module » Convert expectation-less test mocks to stubs - Link module
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Wasn't 100% sure how to test this one but applying the MR and searching for $this->any() and all instances appear to be replaced.

Tests are green so LGTM

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.

dcam’s picture

Status: Reviewed & tested by the community » Needs review

Back to NR because I had to fix mocks from recent commits.

dcam’s picture

Issue summary: View changes
dcam’s picture

Status: Needs review » Needs work

Needs work due to PHPUnit 12.5.11 and a new deprecation.

dcam’s picture

Issue summary: View changes
Status: Needs work » Needs review

New development: stubs cannot set with(). The IS and MR have been updated.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Additional changes for with() LGTM

dcam’s picture

The MR needed a rebase due to the removal of the contact module. A contact file edited in the MR was deleted. I am leaving the status at RTBC.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

core/modules/link/tests/src/Unit/Plugin/migrate/process/FieldLinkTest.php was removed in #3572280: Remove Migrate Drupal, the MR isn't showing it but it won't apply locally because of this - needs rebase.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

Rebased

  • longwave committed 43c31284 on 11.x
    test: #3566476 Convert expectation-less test mocks to stubs - Link...

  • longwave committed c34374f1 on main
    test: #3566476 Convert expectation-less test mocks to stubs - Link...
longwave’s picture

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

Committed and pushed c34374f1282 to main and 43c31284325 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.

Status: Fixed » Closed (fixed)

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