Review main Merged

80735[BUGFIX] Avoid static state in LocalizationUtility

Christian Kuhn CR +2 V +2 Normal +24 −57 updated 08/28/23, 19:33

Commit message

The extbase ConfigurationManager is (unfortunately)
a stateful singleton that we can not get rid of
without a bigger rewrite.

While stateful singletons are bad enough, the
extbase LocalizationUtility makes this worse by
parking an instance of ConfigurationManager in
a static property, re-using it as a "cached"
singleton.

LocalizationUtility does this since it in itself
is static, which makes this service just so
convenient to use. When it comes to sub requests
and similar, static state is doomed and we need
to get rid of it, we've had a couple of patches
in v12 dealing with similar things.

Mid-term, extbase LocalizationUtility needs to
vanish anyways, but in the meantime, we have to
get rid of static state that kills sub request scope.

The patch removes the static $configurationManager
property and adapts functional tests that already
showed the current solution was a hack. There are
various upper and lower cache layers that ensure
removing this "cache layer" won't make things more
expensive in practice, which allows us to remove
this static state without further fallback.

In main, this needs a TF update:

> composer u typo3/testing-framework

In 12.4, this need a TF raise:

> composer req --dev typo3/testing-framework:^8.0.3

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Benjamin Franzke +1
    • Thomas Hohn +1
    • Garvin Hicking +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Benjamin Franzke +1
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 3

Review log 1318

  1. Christian Kuhn uploaded patch set 1 08/28/23, 15:51

  2. core-ci voted on patch set 1 V -1 08/28/23, 15:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45924

  3. Christian Kuhn updated the commit message in patch set 2 V -1 08/28/23, 16:15

  4. core-ci voted on patch set 2 V -1 08/28/23, 16:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45927

  5. Christian Kuhn uploaded patch set 3 V -1 08/28/23, 16:30

  6. core-ci voted on patch set 3 V +1 08/28/23, 16:37 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45928

  7. Benjamin Franzke voted on patch set 3 CR +1 08/28/23, 16:56

  8. Christian Kuhn uploaded patch set 4 CR +1 V +1 08/28/23, 17:31

  9. core-ci voted on patch set 4 V +1 08/28/23, 17:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45930

  10. Christian Kuhn updated the commit message in patch set 5 V +1 08/28/23, 18:10

  11. Benjamin Franzke voted on patch set 5 V +1 CR +1 08/28/23, 18:14

  12. Oliver Klee commented on patch set 5 08/28/23, 18:20

    LocalizationUtilityTest.php:36

    To reduce code duplication and simplify things a bit, we can keep creating the mock configuration manager here, set it as a singleton instance, and only attach the `method` calls in the tests. What do you think?
  13. core-ci voted on patch set 5 V +1 08/28/23, 18:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45935

  14. Thomas Hohn voted on patch set 5 CR +1 08/28/23, 18:29

  15. Christian Kuhn commented on patch set 5 08/28/23, 18:31

    LocalizationUtilityTest.php:36 Reply

    bad idea, imho: a) state / properties in tests should be avoided whenever possible. b) setUp() should be avoided whenever possible c) we're actively getting rid of 'accessible mocks' and 'partial mocks' and 'mocks of the system under test'. all those suck. d) better have code duplication in tests for simplicity than abstraction. tests should be simple. that's one reason in remove setUp() wherever i can since years already. it helps: they become more easy and more easy to refactor. tests must not be a hindrance to refactor SuT, but a help to verify SuT refactorings are ok. -> no mock configuration of this detail in setUp().
  16. Garvin Hicking voted on patch set 5 V +1 CR +1 08/28/23, 19:27

  17. Christian Kuhn voted on patch set 5 V +2 CR +2 08/28/23, 19:32

  18. Christian Kuhn merged patch set 6 08/28/23, 19:33