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

Command icon 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:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review

Creating 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.

spokje’s picture

Status: Needs review » Reviewed & tested by the community

Explanation and code changes make sense. Overall a nice cleanup!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Can 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.

mondrake’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

Updated IS, hopefully it makes sense.

alexpott’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 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.

  • alexpott committed bdcf4705 on 10.2.x
    Issue #3433086 by mondrake: Method addMethods() of class PHPUnit\...

  • alexpott committed 4869fb9a on 10.3.x
    Issue #3433086 by mondrake: Method addMethods() of class PHPUnit\...

  • alexpott committed b73c68de on 11.x
    Issue #3433086 by mondrake: Method addMethods() of class PHPUnit\...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.