[TASK] Use constructor injection in QueryFactory 31/59631/3
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Mon, 4 Feb 2019 14:07:45 +0000 (15:07 +0100)
committerMathias Brodala <mbrodala@pagemachine.de>
Wed, 6 Feb 2019 09:23:54 +0000 (10:23 +0100)
Class QueryFactory does no longer use setter injection but
constructor injection instead.

Releases: master
Resolves: #87642
Change-Id: I5d595ff2c9b5b7e81f5d6380eef1284e0e2d9739
Reviewed-on: https://review.typo3.org/59631
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
typo3/sysext/extbase/Classes/Persistence/Generic/QueryFactory.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryFactoryTest.php

index 6d35b8f..e1a7dee 100644 (file)
@@ -37,25 +37,16 @@ class QueryFactory implements QueryFactoryInterface, \TYPO3\CMS\Core\SingletonIn
 
     /**
      * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
-     */
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
-    {
-        $this->objectManager = $objectManager;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
-     */
-    public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
-    {
-        $this->configurationManager = $configurationManager;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory
      */
-    public function injectDataMapFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory)
-    {
+    public function __construct(
+        \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager,
+        \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager,
+        \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory
+    ) {
+        $this->objectManager = $objectManager;
+        $this->configurationManager = $configurationManager;
         $this->dataMapFactory = $dataMapFactory;
     }
 
index 78330b7..1131a34 100644 (file)
@@ -32,6 +32,11 @@ class QueryFactoryTest extends UnitTestCase
     protected $queryFactory;
 
     /**
+     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $objectManager;
+
+    /**
      * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory|\PHPUnit_Framework_MockObject_MockObject
      */
     protected $dataMapFactory;
@@ -43,23 +48,25 @@ class QueryFactoryTest extends UnitTestCase
 
     protected function setUp()
     {
+        /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
+        $this->objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
+
         $this->dataMap = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class)
             ->setMethods(['getIsStatic', 'getRootLevel'])
             ->setConstructorArgs(['Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'])
             ->getMock();
 
-        $this->queryFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory::class, ['dummy']);
-        $this->queryFactory->_set(
-            'configurationManager',
-            $this->createMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class)
-        );
-
         $this->dataMapFactory = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class)
             ->disableOriginalConstructor()
             ->setMethods(['buildDataMap', 'convertClassNameToTableName'])
             ->getMock();
         $this->dataMapFactory->expects($this->any())->method('buildDataMap')->will($this->returnValue($this->dataMap));
-        $this->queryFactory->_set('dataMapFactory', $this->dataMapFactory);
+
+        $this->queryFactory = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory(
+            $this->objectManager,
+            $this->createMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class),
+            $this->dataMapFactory
+        );
     }
 
     public function getStaticAndRootLevelAndExpectedResult()
@@ -82,20 +89,16 @@ class QueryFactoryTest extends UnitTestCase
      */
     public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
     {
-        /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
-        $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
-        $this->queryFactory->_set('objectManager', $objectManager);
-
         $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
         $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
 
         $query = $this->createMock(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class);
-        $objectManager->expects($this->at(0))->method('get')
+        $this->objectManager->expects($this->at(0))->method('get')
             ->with(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class)
             ->will($this->returnValue($query));
 
         $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-        $objectManager->expects($this->at(1))->method('get')
+        $this->objectManager->expects($this->at(1))->method('get')
             ->with(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class)
             ->will($this->returnValue($querySettings));
         $query->expects($this->once())->method('setQuerySettings')->with($querySettings);