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.

This issue has a cross-module scope. MigrateProcessTestCase is a parent class to many Unit test classes for Migrate Process plugins in Drupal Core. Unfortunately, it creates MockObject properties for which most of these children don't set expectations or don't use at all. The result is dozens of PHPUnit 12 notices in multiple modules.

Steps to reproduce

  1. Require PHPUnit 12 with Composer.
  2. Fix any issues that Core has with running tests on PHPUnit 12.
  3. Run the Unit tests for a module.
  4. Observe the PHPUnit notices that occur.

Proposed resolution

Converting the MigrateProcessTestCase properties to stubs fixes the notices without causing too many secondary problems. Only a handful of classes set expectations for the properties. In those instances, reset the property with a MockObject.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3569415

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

dcam’s picture

The classes modified by this MR are not affected by the new deprecation in PHPUnit 12.5.11.

smustgrave’s picture

Status: Needs review » Needs work

Sorry for taking so long, this one needs a rebase after the migration removals.

dcam’s picture

Status: Needs work » Needs review

Rebased, removing the tests that were deleted due to the removal of migrate_drupal.

dcam’s picture

Status: Needs review » Closed (duplicate)

Because the migrate_drupal-related process plugins were deleted this MR became smaller in scope. I've merged the changes into #3569422: Convert expectation-less test mocks to stubs - Migrate modules.

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.