[BUGFIX] Properly reset package manager in unit tests 21/48421/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 31 May 2016 14:06:49 +0000 (16:06 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 31 May 2016 17:09:12 +0000 (19:09 +0200)
Package manager is a static property in ExtensionManagementUtility
that needs proper reset if a test fiddled with it.
Use the proxy class at places where this is not done yet.

Change-Id: I86d3813e1a4cbcb24c05507923694e498ffcb03d
Resolves: #76402
Releases: master
Reviewed-on: https://review.typo3.org/48421
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/install/Tests/Unit/Controller/Action/Ajax/ExtensionCompatibilityTesterTest.php
typo3/sysext/install/Tests/Unit/Service/SilentConfigurationUpgradeServiceTest.php
typo3/sysext/install/Tests/Unit/Updates/ContentTypesToTextMediaUpdateTest.php

index 4c09f76..5ed14d2 100644 (file)
@@ -14,8 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Unit\TypoScript;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for \TYPO3\CMS\Core\TypoScript\TemplateService
@@ -33,9 +33,12 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     protected $templateServiceMock;
 
     /**
-     * Sets up this test case.
-     *
-     * @return void
+     * @var \TYPO3\CMS\Core\Package\PackageManager
+     */
+    protected $backupPackageManager;
+
+    /**
+     * Set up
      */
     protected function setUp()
     {
@@ -44,6 +47,16 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $this->templateService->tt_track = false;
         $this->templateServiceMock = $this->getAccessibleMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, array('dummy'));
         $this->templateServiceMock->tt_track = false;
+        $this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
+    }
+
+    /**
+     * Tear down
+     */
+    public function tearDown()
+    {
+        ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backupPackageManager);
+        parent::tearDown();
     }
 
     /**
@@ -108,8 +121,6 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $this->assertTrue(
             in_array('test.Core.TypoScript = 1', $this->templateService->config)
         );
-
-        ExtensionManagementUtility::setPackageManager(GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\PackageManager::class));
     }
 
     /**
index faa9aa0..a5b8322 100644 (file)
@@ -20,6 +20,7 @@ use org\bovigo\vfs\vfsStreamWrapper;
 use TYPO3\CMS\Core\Package\Package;
 use TYPO3\CMS\Core\Package\PackageManager;
 use TYPO3\CMS\Core\Tests\FileStreamWrapper;
+use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy;
 use TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\GeneralUtilityFilesystemFixture;
 use TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\GeneralUtilityFixture;
 use TYPO3\CMS\Core\Tests\Unit\Utility\Fixtures\GeneralUtilityMinifyJavaScriptFixture;
@@ -41,6 +42,14 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     protected $singletonInstances = array();
 
+    /**
+     * @var \TYPO3\CMS\Core\Package\PackageManager
+     */
+    protected $backupPackageManager;
+
+    /**
+     * Set up
+     */
     protected function setUp()
     {
         GeneralUtilityFixture::flushInternalRuntimeCaches();
@@ -48,11 +57,16 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         GeneralUtilityFixture::setAllowHostHeaderValue(false);
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = GeneralUtility::ENV_TRUSTED_HOSTS_PATTERN_ALLOW_ALL;
         $this->singletonInstances = GeneralUtility::getSingletonInstances();
+        $this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
     }
 
+    /**
+     * Tear down
+     */
     protected function tearDown()
     {
         GeneralUtility::resetSingletonInstances($this->singletonInstances);
+        ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backupPackageManager);
         parent::tearDown();
     }
 
@@ -4227,9 +4241,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
         $result = GeneralUtility::getFileAbsFileName($path);
         $this->assertEquals($expected, $result);
-
-        // Reset the package manager to use the original one again
-        ExtensionManagementUtility::setPackageManager(GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\PackageManager::class));
     }
 
     /**
index 013b161..60c50ec 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Install\Tests\Unit\Controller\Action\Ajax;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -29,25 +30,18 @@ class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
 
     /**
      * Set up
-     *
-     * @return void
      */
     protected function setUp()
     {
-        // Package manager is mocked in some tests. Backup the original one here to re-inject it to
-        // ExtensionManagementUtility in tearDown() again. makeInstance() is allowed to be used here
-        // since the PackageManager is registered as singleton by bootstrap.
-        $this->backupPackageManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
+        $this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
     }
 
     /**
      * Tear down
-     *
-     * @return void
      */
     protected function tearDown()
     {
-        ExtensionManagementUtility::setPackageManager($this->backupPackageManager);
+        ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backupPackageManager);
         if (file_exists(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt')) {
             unlink(PATH_site . 'typo3temp/assets/ExtensionCompatibilityTester.txt');
         }
index 359da5d..5413dbe 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Install\Service;
 
 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
 use TYPO3\CMS\Core\Package\PackageManager;
+use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Install\Controller\Exception\RedirectException;
 
@@ -30,6 +31,28 @@ class SilentConfigurationUpgradeServiceTest extends \TYPO3\CMS\Core\Tests\UnitTe
     protected $configurationManager;
 
     /**
+     * @var \TYPO3\CMS\Core\Package\UnitTestPackageManager A backup of unit test package manager
+     */
+    protected $backupPackageManager;
+
+    /**
+     * Set up
+     */
+    protected function setUp()
+    {
+        $this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
+    }
+
+    /**
+     * Tear down
+     */
+    protected function tearDown()
+    {
+        ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backupPackageManager);
+        parent::tearDown();
+    }
+
+    /**
      * @param array $methods
      */
     protected function createConfigurationManagerWithMockedMethods(array $methods)
index b696990..02362d7 100644 (file)
@@ -18,6 +18,7 @@ use Prophecy\Prophecy\ObjectProphecy;
 use Prophecy\Prophet;
 use TYPO3\CMS\Core\Package\PackageManager;
 use TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase;
+use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Install\Updates\ContentTypesToTextMediaUpdate as UpdateWizard;
 
@@ -37,10 +38,18 @@ class ContentTypesToTextMediaUpdateTest extends BaseTestCase
     protected $dbProphecy;
 
     /**
+     * @var \TYPO3\CMS\Core\Package\PackageManager
+     */
+    protected $backupPackageManager;
+
+    /**
      * @var ObjectProphecy
      */
     protected $updateWizard;
 
+    /**
+     * Set up
+     */
     public function setUp()
     {
         unset($GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone']);
@@ -49,12 +58,17 @@ class ContentTypesToTextMediaUpdateTest extends BaseTestCase
         $this->dbProphecy = $prophet->prophesize(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
         $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
         $this->updateWizard = new UpdateWizard();
+        $this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
         ExtensionManagementUtility::setPackageManager($this->packageManagerProphecy->reveal());
     }
 
+    /**
+     * Tear down
+     */
     public function tearDown()
     {
-        ExtensionManagementUtility::setPackageManager(new PackageManager());
+        ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backupPackageManager);
+        parent::tearDown();
     }
 
     /**