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
- Require PHPUnit 12 with Composer.
- Fix compatibility issues with PHPUnit 12 by applying this patch.
- Run the Unit tests for a module with
--display-phpunit-notices --display-phpunit-deprecations. - Observe the PHPUnit notices that occur.
Proposed resolution
This issue will fix mocks in a number of Core modules where only a single class was affected per module. These include:
- announcements_feed
- big_pipe
- breakpoint
- ckeditor5
- content_moderation
- datetime
- jsonapi
- menu_link_content
- mysql
- navigation
- responsive_image
- shortcut
- sqlite
- workspaces
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-3567121
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:
- 3567121-stub-conversion
changes, plain diff MR !14310
Comments
Comment #3
dcam commentedComment #5
dcam commentedComment #6
smustgrave commentedAppears to need a rebase
Comment #7
dcam commentedRebased
Comment #8
dcam commentedI removed changes to ban and history from the MR since they've been split off to contrib.
Comment #9
dcam commentedNeeds work due to PHPUnit 12.5.11 and a new deprecation.
The deprecations are in responsive_image.
Comment #10
dcam commentedNew development: stubs cannot set
with(). The IS and MR have been updated.Comment #11
dcam commentedComment #12
smustgrave commentedReviewed this like the others
Uses of any() appear to be replaced. Checking stub vs mock and the ones replaced make sense (leaning on the other tickets for this check)
And results are still green.
LGTM
Comment #13
catchNeeds a rebase.
Comment #14
smustgrave commentedRebased for @dcam. Issue was core/modules/datetime/tests/src/Unit/Plugin/migrate/field/DateFieldTest.php which was deleted when migrate drupal was removed.
Comment #16
catchCommitted/pushed to main, thanks!
This doesn't cherry-pick cleanly to 11.x so leaving it in just main.