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
- Require PHPUnit 12 with Composer.
- Fix any issues that Core has with running tests on PHPUnit 12.
- Run the Unit tests for a module.
- 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
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:
- 3569415-stub-conversion
changes, plain diff MR !14479
Comments
Comment #3
dcam commentedComment #4
dcam commentedThe classes modified by this MR are not affected by the new deprecation in PHPUnit 12.5.11.
Comment #5
smustgrave commentedSorry for taking so long, this one needs a rebase after the migration removals.
Comment #6
dcam commentedRebased, removing the tests that were deleted due to the removal of migrate_drupal.
Comment #7
dcam commentedBecause 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.