[BUGFIX] Backup singletons in unit tests prior to other setUp operations 99/22899/2
authorNicole Cordes <typo3@cordes.co>
Tue, 6 Aug 2013 10:22:51 +0000 (12:22 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 7 Aug 2013 03:17:28 +0000 (05:17 +0200)
If the singleton management is changed in unit tests, a local copy of
the previous stage is done to re-construct this state in tearDown().
This has to be done before any other instantiation in setUp() is
initiated which might register additional singletons.

Resolves: #50812
Releases: 6.2, 6.1, 6.0
Change-Id: I7788a5788aca6777040b777aeceb0558f96022b2
Reviewed-on: https://review.typo3.org/22899
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Tests/Functional/Utility/File/ExtendedFileUtilityTest.php
typo3/sysext/core/Tests/Unit/FormProtection/BackendFormProtectionTest.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Resource/Utility/FileExtensionFilterTest.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionMangementUtilityTest.php
typo3/sysext/fluid/Tests/Unit/View/StandaloneViewTest.php

index d61993c..fce6651 100644 (file)
@@ -84,6 +84,9 @@ class ExtendedFileUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * Sets up this testcase
         */
        public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+               \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
+
                $this->storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
                // Initializing file processor
                $GLOBALS['BE_USER'] = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication', array('getSessionData', 'setAndSaveSessionData'));
@@ -94,8 +97,6 @@ class ExtendedFileUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
                $this->fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions());
                $this->fileProcessor->dontCheckForUnique = 1;
-               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
-               \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
        }
 
        /**
index 878d812..a0ee9ae 100644 (file)
@@ -45,6 +45,8 @@ class BackendFormProtectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * Set up
         */
        public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+
                $GLOBALS['BE_USER'] = $this->getMock(
                        'TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication',
                        array('getSessionData', 'setAndSaveSessionData')
@@ -55,8 +57,6 @@ class BackendFormProtectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'TYPO3\\CMS\\Core\\FormProtection\BackendFormProtection',
                        array('acquireLock', 'releaseLock')
                );
-
-               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
        }
 
        public function tearDown() {
index 0205188..84b9576 100644 (file)
@@ -50,9 +50,9 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
 
        public function setUp() {
                parent::setUp();
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                // use a mocked file repository to avoid updating the index when doing property update tests
                $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository', $mockedRepository);
        }
index 0079dde..70f6b76 100644 (file)
@@ -63,10 +63,10 @@ class FileExtensionFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * Sets up this test suite.
         */
        protected function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                $this->filter = new \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter();
                $this->tceMainMock = $this->getMock('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', array('deleteAction'), array());
                $this->fileFactoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array('getFileReferenceObject'), array());
-               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $this->fileFactoryMock);
        }
 
index 2d0e66e..145c481 100644 (file)
@@ -60,12 +60,12 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
        protected $fakedExtensions = array();
 
        public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                $this->createAccessibleProxyClass();
                $this->globals = array(
                        'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT'])
                );
                $this->testFilesToDelete = array();
-               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
        }
 
        public function tearDown() {
index fd11c2b..9d6520a 100644 (file)
@@ -101,6 +101,7 @@ class StandaloneViewTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         * @return void
         */
        public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                $this->view = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\StandaloneView', array('dummy'), array(), '', FALSE);
                $this->mockTemplateParser = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser');
                $this->mockParsedTemplate = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsedTemplateInterface');
@@ -123,7 +124,6 @@ class StandaloneViewTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->view->setRenderingContext($this->mockRenderingContext);
                $this->mockTemplateCompiler = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Compiler\\TemplateCompiler');
                $this->view->_set('templateCompiler', $this->mockTemplateCompiler);
-               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', $this->mockObjectManager);
                \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', $this->mockContentObject);
        }