[TASK] Use constructor injection in configuration managers 46/59446/3
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Tue, 15 Jan 2019 14:24:57 +0000 (15:24 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Sun, 27 Jan 2019 07:48:04 +0000 (08:48 +0100)
The following classes do no longer use setter injection but
constructor injection instead:

- TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
- TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
- TYPO3\CMS\Extbase\Configuration\ConfigurationManager
- TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager

Releases: master
Resolves: #87448
Change-Id: Ib6df3ab4a286bbe77cdda82d0066495a8dab8b22
Reviewed-on: https://review.typo3.org/59446
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Christian Wolff <chris@wolffc.de>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Sebastian Fischer <typo3@evoweb.de>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/extbase/Classes/Configuration/AbstractConfigurationManager.php
typo3/sysext/extbase/Classes/Configuration/ConfigurationManager.php
typo3/sysext/extbase/Classes/Configuration/FrontendConfigurationManager.php
typo3/sysext/extbase/Tests/Functional/Configuration/BackendConfigurationManagerTest.php
typo3/sysext/extbase/Tests/Unit/Configuration/AbstractConfigurationManagerTest.php
typo3/sysext/extbase/Tests/Unit/Configuration/BackendConfigurationManagerTest.php
typo3/sysext/extbase/Tests/Unit/Configuration/FrontendConfigurationManagerTest.php

index 9330643..01a91be 100644 (file)
@@ -75,25 +75,16 @@ abstract class AbstractConfigurationManager implements \TYPO3\CMS\Core\Singleton
 
     /**
      * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
-     */
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
-    {
-        $this->objectManager = $objectManager;
-    }
-
-    /**
      * @param \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
-     */
-    public function injectTypoScriptService(\TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService)
-    {
-        $this->typoScriptService = $typoScriptService;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
      */
-    public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
-    {
+    public function __construct(
+        \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager,
+        \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService,
+        \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
+    ) {
+        $this->objectManager = $objectManager;
+        $this->typoScriptService = $typoScriptService;
         $this->environmentService = $environmentService;
     }
 
index 01c26fe..4941e97 100644 (file)
@@ -16,7 +16,7 @@ namespace TYPO3\CMS\Extbase\Configuration;
 
 /**
  * A configuration manager following the strategy pattern (GoF315). It hides the concrete
- * implementation of the configuration manager and provides an unified acccess point.
+ * implementation of the configuration manager and provides an unified access point.
  *
  * Use the shutdown() method to drop the concrete implementation.
  * @internal only to be used within Extbase, not part of TYPO3 Core API.
@@ -40,25 +40,15 @@ class ConfigurationManager implements \TYPO3\CMS\Extbase\Configuration\Configura
 
     /**
      * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
-     */
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
-    {
-        $this->objectManager = $objectManager;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
      */
-    public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
-    {
+    public function __construct(
+        \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager,
+        \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
+    ) {
+        $this->objectManager = $objectManager;
         $this->environmentService = $environmentService;
-    }
 
-    /**
-     * Initializes the object
-     */
-    public function initializeObject()
-    {
         $this->initializeConcreteConfigurationManager();
     }
 
index 24ad2a1..75442e9 100644 (file)
@@ -31,10 +31,19 @@ class FrontendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abst
     protected $flexFormService;
 
     /**
+     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
+     * @param \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
+     * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
      * @param \TYPO3\CMS\Core\Service\FlexFormService $flexFormService
      */
-    public function injectFlexFormService(\TYPO3\CMS\Core\Service\FlexFormService $flexFormService)
-    {
+    public function __construct(
+        \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager,
+        \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService,
+        \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService,
+        \TYPO3\CMS\Core\Service\FlexFormService $flexFormService
+    ) {
+        parent::__construct($objectManager, $typoScriptService, $environmentService);
+
         $this->flexFormService = $flexFormService;
     }
 
index b2870d3..f716077 100644 (file)
@@ -31,7 +31,7 @@ class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Funct
      */
     public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound()
     {
-        $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
+        $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup'], [], '', false);
         $mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
         $backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
 
@@ -56,7 +56,7 @@ class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Funct
      */
     public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet()
     {
-        $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
+        $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup'], [], '', false);
         $mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
         $backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
 
@@ -80,7 +80,7 @@ class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Funct
      */
     public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound()
     {
-        $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
+        $backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup'], [], '', false);
         $mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
         $backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
 
index 44d8d8c..73ba1a3 100644 (file)
@@ -128,7 +128,10 @@ class AbstractConfigurationManagerTest extends UnitTestCase
                 'getPluginConfiguration',
                 'getSwitchableControllerActions',
                 'getRecursiveStoragePids'
-            ]
+            ],
+            [],
+            '',
+            false
         );
         $this->mockTypoScriptService = $this->getAccessibleMock(TypoScriptService::class);
         $this->abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
@@ -399,7 +402,10 @@ class AbstractConfigurationManagerTest extends UnitTestCase
                 'getPluginConfiguration',
                 'getSwitchableControllerActions',
                 'getRecursiveStoragePids'
-            ]
+            ],
+            [],
+            '',
+            false
         );
         $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
         $abstractConfigurationManager->setConfiguration(['switchableControllerActions' => ['overriddenSwitchableControllerActions']]);
@@ -428,7 +434,10 @@ class AbstractConfigurationManagerTest extends UnitTestCase
                 'getPluginConfiguration',
                 'getSwitchableControllerActions',
                 'getRecursiveStoragePids'
-            ]
+            ],
+            [],
+            '',
+            false
         );
         $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
         $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
@@ -454,7 +463,10 @@ class AbstractConfigurationManagerTest extends UnitTestCase
                 'getPluginConfiguration',
                 'getSwitchableControllerActions',
                 'getRecursiveStoragePids'
-            ]
+            ],
+            [],
+            '',
+            false
         );
         $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($configuration)->will($this->returnValue($configuration));
         $abstractConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
index 61731b0..8ecec56 100644 (file)
@@ -38,7 +38,13 @@ class BackendConfigurationManagerTest extends UnitTestCase
      */
     protected function setUp()
     {
-        $this->backendConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['getTypoScriptSetup']);
+        $this->backendConfigurationManager = $this->getAccessibleMock(
+            \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class,
+            ['getTypoScriptSetup'],
+            [],
+            '',
+            false
+        );
         $this->mockTypoScriptService = $this->getAccessibleMock(\TYPO3\CMS\Core\TypoScript\TypoScriptService::class);
         $this->backendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
     }
@@ -307,7 +313,13 @@ class BackendConfigurationManagerTest extends UnitTestCase
         $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
         $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
 
-        $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class,
+            ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'],
+            [],
+            '',
+            false
+        );
         $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
         $queryGenerator->expects($this->any())
             ->method('getTreeList')
@@ -332,7 +344,13 @@ class BackendConfigurationManagerTest extends UnitTestCase
         $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
         $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
 
-        $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getQueryGenerator']);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class,
+            ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getQueryGenerator'],
+            [],
+            '',
+            false
+        );
         $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
         $queryGenerator->expects($this->any())
             ->method('getTreeList')
@@ -351,7 +369,13 @@ class BackendConfigurationManagerTest extends UnitTestCase
     {
         $storagePid = '1,2,3';
 
-        $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class,
+            ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'],
+            [],
+            '',
+            false
+        );
 
         $expectedResult = '1,2,3';
         $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
@@ -366,7 +390,13 @@ class BackendConfigurationManagerTest extends UnitTestCase
         $storagePid = '1,2,3';
         $recursive = 0;
 
-        $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class,
+            ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'],
+            [],
+            '',
+            false
+        );
 
         $expectedResult = '1,2,3';
         $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
index 66d5449..7b53ab2 100644 (file)
@@ -54,7 +54,13 @@ class FrontendConfigurationManagerTest extends UnitTestCase
         $this->mockContentObject = $this->getMockBuilder(ContentObjectRenderer::class)
             ->setMethods(['getTreeList'])
             ->getMock();
-        $this->frontendConfigurationManager = $this->getAccessibleMock(FrontendConfigurationManager::class, ['dummy']);
+        $this->frontendConfigurationManager = $this->getAccessibleMock(
+            FrontendConfigurationManager::class,
+            ['dummy'],
+            [],
+            '',
+            false
+        );
         $this->frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
         $this->mockTypoScriptService = $this->getAccessibleMock(TypoScriptService::class);
         $this->frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);
@@ -372,11 +378,17 @@ class FrontendConfigurationManagerTest extends UnitTestCase
             ]
         ];
         /** @var FrontendConfigurationManager|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface */
-        $frontendConfigurationManager = $this->getAccessibleMock(FrontendConfigurationManager::class, [
-            'overrideStoragePidIfStartingPointIsSet',
-            'overrideConfigurationFromPlugin',
-            'overrideConfigurationFromFlexForm'
-        ]);
+        $frontendConfigurationManager = $this->getAccessibleMock(
+            FrontendConfigurationManager::class,
+            [
+                'overrideStoragePidIfStartingPointIsSet',
+                'overrideConfigurationFromPlugin',
+                'overrideConfigurationFromFlexForm'
+            ],
+            [],
+            '',
+            false
+        );
         $frontendConfigurationManager->expects($this->at(0))->method('overrideStoragePidIfStartingPointIsSet')->with($frameworkConfiguration)->will($this->returnValue(['overridden' => 'storagePid']));
         $frontendConfigurationManager->expects($this->at(1))->method('overrideConfigurationFromPlugin')->with(['overridden' => 'storagePid'])->will($this->returnValue(['overridden' => 'pluginConfiguration']));
         $frontendConfigurationManager->expects($this->at(2))->method('overrideConfigurationFromFlexForm')->with(['overridden' => 'pluginConfiguration'])->will($this->returnValue(['overridden' => 'flexFormConfiguration']));
@@ -396,13 +408,19 @@ class FrontendConfigurationManagerTest extends UnitTestCase
         $storagePid = '3,5,9';
         $recursive = 99;
         /** @var $abstractConfigurationManager FrontendConfigurationManager */
-        $abstractConfigurationManager = $this->getAccessibleMock(FrontendConfigurationManager::class, [
-            'overrideSwitchableControllerActions',
-            'getContextSpecificFrameworkConfiguration',
-            'getTypoScriptSetup',
-            'getPluginConfiguration',
-            'getSwitchableControllerActions'
-        ]);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            FrontendConfigurationManager::class,
+            [
+                'overrideSwitchableControllerActions',
+                'getContextSpecificFrameworkConfiguration',
+                'getTypoScriptSetup',
+                'getPluginConfiguration',
+                'getSwitchableControllerActions'
+            ],
+            [],
+            '',
+            false
+        );
         /** @var $cObjectMock ContentObjectRenderer */
         $cObjectMock = $this->createMock(ContentObjectRenderer::class);
         $cObjectMock->expects($this->any())
@@ -423,13 +441,19 @@ class FrontendConfigurationManagerTest extends UnitTestCase
         $storagePid = '-3,5,9';
         $recursive = 99;
         /** @var $abstractConfigurationManager FrontendConfigurationManager */
-        $abstractConfigurationManager = $this->getAccessibleMock(FrontendConfigurationManager::class, [
-            'overrideSwitchableControllerActions',
-            'getContextSpecificFrameworkConfiguration',
-            'getTypoScriptSetup',
-            'getPluginConfiguration',
-            'getSwitchableControllerActions'
-        ]);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            FrontendConfigurationManager::class,
+            [
+                'overrideSwitchableControllerActions',
+                'getContextSpecificFrameworkConfiguration',
+                'getTypoScriptSetup',
+                'getPluginConfiguration',
+                'getSwitchableControllerActions'
+            ],
+            [],
+            '',
+            false
+        );
         /** @var $cObjectMock ContentObjectRenderer */
         $cObjectMock = $this->createMock(ContentObjectRenderer::class);
         $cObjectMock->expects($this->any())
@@ -450,13 +474,19 @@ class FrontendConfigurationManagerTest extends UnitTestCase
         $storagePid = '1,2,3';
 
         /** @var $abstractConfigurationManager FrontendConfigurationManager */
-        $abstractConfigurationManager = $this->getAccessibleMock(FrontendConfigurationManager::class, [
-            'overrideSwitchableControllerActions',
-            'getContextSpecificFrameworkConfiguration',
-            'getTypoScriptSetup',
-            'getPluginConfiguration',
-            'getSwitchableControllerActions'
-        ]);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            FrontendConfigurationManager::class,
+            [
+                'overrideSwitchableControllerActions',
+                'getContextSpecificFrameworkConfiguration',
+                'getTypoScriptSetup',
+                'getPluginConfiguration',
+                'getSwitchableControllerActions'
+            ],
+            [],
+            '',
+            false
+        );
         /** @var $cObjectMock ContentObjectRenderer */
         $cObjectMock = $this->createMock(ContentObjectRenderer::class);
         $cObjectMock->expects($this->never())->method('getTreeList');
@@ -475,13 +505,19 @@ class FrontendConfigurationManagerTest extends UnitTestCase
         $storagePid = '1,2,3';
         $recursive = 0;
 
-        $abstractConfigurationManager = $this->getAccessibleMock(FrontendConfigurationManager::class, [
-            'overrideSwitchableControllerActions',
-            'getContextSpecificFrameworkConfiguration',
-            'getTypoScriptSetup',
-            'getPluginConfiguration',
-            'getSwitchableControllerActions'
-        ]);
+        $abstractConfigurationManager = $this->getAccessibleMock(
+            FrontendConfigurationManager::class,
+            [
+                'overrideSwitchableControllerActions',
+                'getContextSpecificFrameworkConfiguration',
+                'getTypoScriptSetup',
+                'getPluginConfiguration',
+                'getSwitchableControllerActions'
+            ],
+            [],
+            '',
+            false
+        );
 
         /** @var $cObjectMock ContentObjectRenderer */
         $cObjectMock = $this->createMock(ContentObjectRenderer::class);
@@ -648,7 +684,10 @@ class FrontendConfigurationManagerTest extends UnitTestCase
         /** @var $frontendConfigurationManager FrontendConfigurationManager */
         $frontendConfigurationManager = $this->getAccessibleMock(
             FrontendConfigurationManager::class,
-            ['getTypoScriptSetup']
+            ['getTypoScriptSetup'],
+            [],
+            '',
+            false
         );
         $frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
         $frontendConfigurationManager->_set('typoScriptService', $this->mockTypoScriptService);