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 core/tests/Drupal/Tests/Core/Menu. There are plenty of notices to fix in the standalone tests, but the impact of this reaches farther because of LocalTaskIntegrationTestBase. Many of the Core modules extend this base class. It's responsible for a lot of the remaining module notices, which is the reason why these tests are the first group from the Core libraries to be fixed.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3579136
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:
- 3579136-mockobject-fixes
changes, plain diff MR !15087
Comments
Comment #3
dcam commentedComment #4
smustgrave commentedFollowing the steps of downloading phpunit12 and applying the one patch with the MR I get OK (93 tests, 416 assertions) all notices are gone.
Comment #5
catchLooks good to me. Thanks for doing the self-review comments on the MRs, makes it much easier to commit vs. staring at the slightly trickier changes.
Committed/pushed to main, thanks!