[TASK] Use constructor injection in DataMapFactory 05/59305/5
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Sun, 30 Dec 2018 13:20:03 +0000 (14:20 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 11 Jan 2019 16:10:29 +0000 (17:10 +0100)
Class DataMapFactory does no longer use setter injection but
constructor injection instead.

Releases: master
Resolves: #87306
Change-Id: Id6d2ff14862e96e39cf776fc6a9ed714ec6eb952
Reviewed-on: https://review.typo3.org/59305
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapFactoryTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryFactoryTest.php

index c6dcbbc..beab144 100644 (file)
@@ -56,41 +56,21 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
 
     /**
      * @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService
-     */
-    public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
-    {
-        $this->reflectionService = $reflectionService;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
-     */
-    public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
-    {
-        $this->configurationManager = $configurationManager;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
-     */
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
-    {
-        $this->objectManager = $objectManager;
-    }
-
-    /**
      * @param \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
      */
-    public function injectCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
-    {
+    public function __construct(
+        \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService,
+        \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager,
+        \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager,
+        \TYPO3\CMS\Core\Cache\CacheManager $cacheManager
+    ) {
+        $this->reflectionService = $reflectionService;
+        $this->configurationManager = $configurationManager;
+        $this->objectManager = $objectManager;
         $this->cacheManager = $cacheManager;
-    }
 
-    /**
-     * Lifecycle method
-     */
-    public function initializeObject()
-    {
         $this->dataMapCache = $this->cacheManager->getCache('extbase_datamapfactory_datamap');
     }
 
index 47eb49e..7146014 100644 (file)
@@ -424,8 +424,13 @@ class DataMapFactoryTest extends UnitTestCase
             $mockColumnMap->expects($this->never())->method('setDateTimeStorageFormat');
         }
 
-        $accessibleClassName = $this->buildAccessibleProxy(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class);
-        $accessibleDataMapFactory = new $accessibleClassName();
+        $accessibleDataMapFactory = $this->getAccessibleMock(
+            \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class,
+            ['dummy'],
+            [],
+            '',
+            false
+        );
         $accessibleDataMapFactory->_callRef('setFieldEvaluations', $mockColumnMap, $columnDefinition);
     }
 
@@ -520,7 +525,7 @@ class DataMapFactoryTest extends UnitTestCase
      */
     public function resolveTableNameReturnsExpectedTablenames($className, $expected)
     {
-        $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['dummy']);
+        $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['dummy'], [], '', false);
         $this->assertSame($expected, $dataMapFactory->_call('resolveTableName', $className));
     }
 
@@ -530,7 +535,7 @@ class DataMapFactoryTest extends UnitTestCase
     public function createColumnMapReturnsAValidColumnMap()
     {
         /** @var $dataMapFactory \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory */
-        $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['dummy']);
+        $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['dummy'], [], '', false);
 
         /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
         $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
@@ -582,7 +587,7 @@ class DataMapFactoryTest extends UnitTestCase
     public function setTypeDetectsTypeAndInternalTypeProperly(array $columnConfiguration, $type, $internalType)
     {
         /** @var $dataMapFactory \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory | AccessibleObjectInterface */
-        $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['dummy']);
+        $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['dummy'], [], '', false);
 
         /** @var ColumnMap $columnMap */
         $columnMap = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, ['dummy'], [], '', false);
index 42e983e..78330b7 100644 (file)
@@ -55,6 +55,7 @@ class QueryFactoryTest extends UnitTestCase
         );
 
         $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));