[TASK] Fix for unit tests to change singletons and reset again
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 9 Sep 2012 23:02:59 +0000 (01:02 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 9 Sep 2012 23:42:35 +0000 (01:42 +0200)
commit4fd6bfa23d2670d5a4c03790a7066171fbe34ff7
treea576d3dc9f3624562d4fcb40089a9a37d8736b3c
parent530fe3bcbee4ccd2d5be287452d474b29ca92b08
[TASK] Fix for unit tests to change singletons and reset again

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.

Change-Id: I19dc869423a537226bb019e227d84b6f74fe9afc
Resolves: #40780
Releases: 6.0
Reviewed-on: http://review.typo3.org/14487
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
12 files changed:
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/DataHandler/DataHandlerTest.php
typo3/sysext/core/Tests/Unit/Extension/ExtensionManagerTest.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Resource/FactoryTest.php
typo3/sysext/core/Tests/Unit/Resource/FileTest.php
typo3/sysext/core/Tests/Unit/Resource/FolderTest.php
typo3/sysext/core/Tests/Unit/Resource/StorageTest.php
typo3/sysext/core/Tests/Unit/Resource/Utility/FileExtensionFilterTest.php
typo3/sysext/core/Tests/Unit/Utility/File/ExtendedFileUtilityTest.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/core/Tests/Unit/Utility/MailUtilityTest.php