Method addMethods() of class PHPUnit\Framework\MockObject\MockBuilder is deprecated in PHPUnit 10

Created on 22 March 2024, 6 months ago
Updated 9 April 2024, 5 months ago

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

📌 Task
Status

Fixed

Version

10.2

Component
PHPUnit 

Last updated about 11 hours ago

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mondrake
  • Merge request !7166Closes #3433086 → (Open) created by mondrake
  • Pipeline finished with Failed
    6 months ago
    Total: 542s
    #126653
  • Pipeline finished with Failed
    6 months ago
    Total: 590s
    #127604
  • Pipeline finished with Failed
    6 months ago
    Total: 698s
    #127615
  • Pipeline finished with Failed
    6 months ago
    Total: 562s
    #127735
  • Pipeline finished with Failed
    6 months ago
    Total: 187s
    #127746
  • Pipeline finished with Success
    6 months ago
    Total: 561s
    #127758
  • Pipeline finished with Success
    6 months ago
    Total: 544s
    #127773
  • Pipeline finished with Canceled
    6 months ago
    Total: 76s
    #127811
  • Pipeline finished with Canceled
    6 months ago
    Total: 69s
    #127813
  • Pipeline finished with Failed
    6 months ago
    Total: 620s
    #127815
  • Status changed to Needs review 6 months ago
  • 🇮🇹Italy mondrake 🇮🇹

    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.

  • Pipeline finished with Success
    6 months ago
    Total: 491s
    #127849
  • Status changed to RTBC 6 months ago
  • 🇳🇱Netherlands Spokje

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

  • Status changed to Needs work 6 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    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.

  • Status changed to RTBC 6 months ago
  • 🇮🇹Italy mondrake 🇮🇹

    Updated IS, hopefully it makes sense.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    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\...
  • Status changed to Fixed 6 months ago
    • alexpott committed b73c68de on 11.x
      Issue #3433086 by mondrake: Method addMethods() of class PHPUnit\...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024