Review main Merged

78223[TASK] Avoid mocking methods that don't exist

Christian Kuhn CR +2 V +2 Hard +70 −203 updated 03/23/23, 15:01

Commit message

phpunit 10 removed ->setMethods() on mocks.

This is especially problematic with
typo3/testing-framework, which provides
->getAccessibleMock(). The scope of this API
is to "open up" sub methods of a class, to check
if they are called with this-or-that argument, and
to return some value as mock, while keeping other
parts of the mocked class as-is.

TF ->getAccessibleMock() will have to change from
using ->setMethods() for phpunit 10 support. It
will switch to ->onlyMethods() instead.

The difference between setMethods() and onlyMethods()
is, that onlyMethods() throws an exception if a
method to-be-mocked method does not exist, while
setMethods() did not do that.

We do *not* want to implement some API within TF
->getAccessibleMock() (and friends) to check if
some method actually exists in a to-mock class,
we'll switch to onlyMethods() and will avoid
additional magic that would be potentially
available using ->addMethods().

As such, we need to get rid of all calls within
the TYPO3 core that try to create mocks of
methods that don't exist.

There are a couple of hard nuts. This patch
solves the easy cases, more complicated
use cases will be sorted out with dedicated
patches. Strategy with this patch:

* Use 'null' instead of ['dummy'] to mock
  no method and only have an accessible proxy.
  'dummy' has been used a lot in the past, has
  been removed a lot already, but left overs
  need to be removed now.
* Avoid mocking methods in tests that have
  been removed meanwhile. That part is the
  good thing of phpunit 10: It forces tests
  to keep up with the system under test in
  case it removed methods, so we don't end
  up with dead method mocks.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Markus Klein +1
    • Nikita Hovratov +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Markus Klein +1
    • Nikita Hovratov +1
    • core-ci +1 CI

Issues 2

Files 19

Review log 913

  1. Christian Kuhn uploaded patch set 1 03/23/23, 06:03

  2. core-ci voted on patch set 1 V -1 03/23/23, 06:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39439

  3. Christian Kuhn uploaded patch set 2 V -1 03/23/23, 13:09

  4. Christian Kuhn updated the commit message in patch set 3 03/23/23, 13:14

  5. Christian Kuhn commented on patch set 3 CR -1 03/23/23, 13:18

    fiddling with details
  6. core-ci voted on patch set 2 V +1 03/23/23, 13:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39471

  7. Christian Kuhn uploaded patch set 4 CR -1 03/23/23, 13:24

  8. core-ci voted on patch set 3 V +1 03/23/23, 13:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39472

  9. core-ci voted on patch set 4 V +1 03/23/23, 13:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39475

  10. Nikita Hovratov voted on patch set 4 V +1 CR +1 03/23/23, 14:41

  11. Markus Klein voted on patch set 4 V +1 CR +1 03/23/23, 14:47

  12. Christian Kuhn voted on patch set 4 V +2 CR +2 03/23/23, 15:01

  13. Christian Kuhn merged patch set 5 03/23/23, 15:01