Problem/Motivation
Method addMethods() of class PHPUnit\Framework\MockObject\MockBuilder is deprecated in PHPUnit 10
Proposed resolution
Adding fictitious double methods to a mock, that do not have a correspondence to real methods, is discouraged.
Rather, use real classes or mock of real classes for testing (if necessary, extending the original class in a test class).
For instance, the mock of a class configured with ::onlyMethods([]) would allow all the real methods to be present, still with the possibility to disable the original constructor (if testing things that do not require the injecting of properties, for example).
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3433086
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:
- 3433086-method-addmethods-of
changes, plain diff MR !7166
Comments
Comment #3
mondrakeCreating dummy doubles that have no correspondence to methods in the SUT is code smell.
Looking at how this was (ab)used, in this case I think the deprecation of this method is really a good step. In some cases we did not even need a mock, in other there were hidden bugs.
Comment #4
spokjeExplanation and code changes make sense. Overall a nice cleanup!
Comment #5
alexpottCan the issue summary be completed. It helps modules that have to replace the same things.
The MR looks great - much better to be be testing with real classes in more places.
Comment #6
mondrakeUpdated IS, hopefully it makes sense.
Comment #7
alexpottCommitted and pushed b73c68de45 to 11.x and 4869fb9aa6 to 10.3.x and bdcf4705fa to 10.2.x. Thanks!
Backported to 10.2.x to keep test coverage aligned.