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
- 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. - 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
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:
- 3569429-stub-conversion
changes, plain diff MR !14488
Comments
Comment #3
dcam commentedComment #4
dcam commentedComment #5
dcam commentedI reverted the changes to the contact module since it has been split off to contrib.
Comment #8
smustgrave commentedPer the other ones seems a new deprecation came out. Not sure if you want to wait for the phpstan issues to land first?
Comment #9
dcam commentedThe 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.Comment #10
smustgrave commentedThis one may be dependent on #3579897: Convert expectation-less test mocks to stubs - Cache library
Comment #11
dcam commentedFYI: the recently-committed
UnitTestCasechanges have been merged into this MR, so they do not need to be applied separately.Comment #12
smustgrave commentedblock_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.
Comment #14
catchCommitted/pushed to main, thanks!