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 library with
--display-phpunit-notices --display-phpunit-deprecations. - Observe the PHPUnit notices that occur.
Proposed resolution
Fix notices in the tests for the following core libraries, which currently only represents 10 affected classes.
core/tests/Drupal/Tests/Core/Lock/core/tests/Drupal/Tests/Core/Logger/core/tests/Drupal/Tests/Core/Mail/core/tests/Drupal/Tests/Core/Path/core/tests/Drupal/Tests/Core/PathPreprocessor/core/tests/Drupal/Tests/Core/PreWarm/
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3579858
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:
- 3579858-mockobject-fixes
changes, plain diff MR !15116
Comments
Comment #2
dcam commentedComment #4
dcam commentedComment #5
smustgrave commentedLock = no deprecations
Logger = no deprecations
Mail =
Path = Got 10 still example
PathPreprocess = got 1
Prewarm = 0
Comment #6
dcam commentedThank you again for pointing them out. I'm going to be better about noting the notices covered by other MRs.
The mentioned notices are covered by #3578904: Convert expectation-less test mocks to stubs - UnitTestCase. When I run the tests without the #3578904 changes I get 14 notices from these tests. When I apply the MR from #3578904 I get 0.
Comment #7
smustgrave commentedRetested mail, path, and pathpreprocess and all 0
Comment #10
catchThis looks fine, some of the tests start to look a bit repetitive - lots of the same method calls in various test methods, but that's something we can look at if someone ever decides to refactor the tests and might not be easy to change anyway.
Committed/pushed to main, thanks!