Review 14.3 Merged

95277[TASK] Remove needless getAccessibleMock() usages

Benni Mack CR +2 V +2 Hard +408 −337 updated 08/12/26, 10:55

Commit message

getAccessibleMock() of the testing framework builds an eval()'d proxy
subclass that adds _call(), _set() and _get() to reach protected
members of the doubled class. A test that never uses one of those
methods gains nothing from the proxy, but pays for it with a generated
class per call and a test double that no longer carries the type of
the class it doubles.

Get rid of it where it is not needed:

* Use a plain getMockBuilder()->onlyMethods() chain in the test classes
  that never touch the accessible API. Protected methods can be
  configured on a regular mock as well, the proxy is not involved in
  that.

* Call methods directly that have become public in the meantime, such
  as PackageManager->scanAvailablePackages(), YamlSource->load() or
  JsonView->assign(). Two of them are static by now, so
  CommandUtility::getCommand() and
  EnableFileService::removeFirstInstallFile() do not need an instance
  at all anymore.

* Use the real class where the double did not double anything: Export,
  FormDefinition and CoreVersionService are instantiated directly,
  FormRuntime, ExtensionRepository and EmConfUtility are stubs now.

* Drop the subject property of ResourceFactoryTest, which has been
  dead since every test creates its own subject.

* Read the protected property with \ReflectionProperty in
  FileBackendTest, the only thing the proxy was used for there.

This brings the number of getAccessibleMock() calls down from 555 to
451 and the number of test classes using it from 105 to 82.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Wouter Wolters +1
  • Verified V +2 Done
    • Benni Mack +2
    • Wouter Wolters +1
    • core-ci +1 CI

Issues 1

Files 30

Show 10 more files

Review log 68

  1. Benni Mack commented on patch set 1 08/12/26, 08:08

    Cherry Picked from branch main. The following files contain Git conflicts: * typo3/sysext/backend/Tests/Unit/Controller/SiteSettingsControllerTest.php * typo3/sysext/core/Tests/Functional/Resource/ResourceFactoryTest.php * typo3/sysext/core/Tests/Unit/DataHandling/SlugHelperTest.php * typo3/sysext/extbase/Tests/Functional/Validation/Validator/CollectionValidatorTest.php * typo3/sysext/form/Tests/Unit/Domain/Configuration/FormDefinitionConversionServiceTest.php * typo3/sysext/frontend/Tests/Unit/Typolink/DatabaseRecordLinkBuilderTest.php * typo3/sysext/redirects/Tests/Unit/Service/RedirectServiceTest.php
  2. core-ci voted on patch set 1 V -1 08/12/26, 08:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/106493

  3. Benni Mack uploaded patch set 2 V -1 08/12/26, 10:44

  4. Benni Mack marked it ready for review 08/12/26, 10:44

  5. core-ci voted on patch set 2 V +1 08/12/26, 10:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/106499

  6. Wouter Wolters voted on patch set 2 CR +1 V +1 08/12/26, 10:53

  7. Benni Mack voted on patch set 2 CR +2 V +2 08/12/26, 10:55

  8. Benni Mack merged patch set 3 08/12/26, 10:55