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

    Imported before Forger kept the single votes, the next import adds them.

  • Verified V +2

    Imported before Forger kept the single votes, the next import adds them.

Issues 2

Files 19