Bug #40780
closedFix for unit tests to change singletons and reset again
100%
Description
TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance() is a method
for unit tests to inject singleton mocks for classes that are
instantiated with makeInstance. purgeInstances() can be used to reset all
registered singletons, so makeInstance() creates new objects after that.
purgeInstances() can change the behaviour of tests that are executed
afterwards, because all registered singletons are reset. Currently the
helper methods for singletons around makeInstance() are not able to get
the list of registered singletons, and reset them to the previous list.
The patch introduces method getSingletonInstances() that returns a list
of all registered singletons (used in setUp()), and method
resetSingletonInstances() that resets registered singletons to a given
stored list (used in tearDown()). This way it is possible to fiddle in
tests with purgeInstances() without introducing side effects to other
tests.
All unit tests that used purgeInstances() are adapted to take care
of re constitution of changed objects this way.