Skip to content
Snippets Groups Projects
Commit 6d10f13b authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[TASK] Avoid mocking methods that don't exist

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.

Resolves: #100273
Related: #100249
Change-Id: If93ec4b87fdad15954ba0c17d868cd8f1165d372
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78223


Tested-by: default avatarNikita Hovratov <nikita.h@live.de>
Tested-by: default avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: default avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: default avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 258fc1c1
Branches
Tags
No related merge requests found
Showing
with 70 additions and 203 deletions
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment