[TASK] Streamline creation of column maps
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Sat, 16 Mar 2013 14:27:42 +0000 (15:27 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 16 Mar 2013 23:15:39 +0000 (00:15 +0100)
Currently the datamap factory calls "new ColumnMap" to create
a column map. This is bad as this cannot be mocked at all. A
method that handles the process of creation should be introduced,
also the object manager should be used to create the object.

Important:
This is neither a feature nor a bugfix but as it behaves like a
feature it will not be backported at all!

Releases: 6.1
Resolves: #46354
Change-Id: Ie27da180b05ba11d902da9c11185d41a3a4a8f05
Reviewed-on: https://review.typo3.org/18975
Reviewed-by: Mattias Nilsson
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapFactoryTest.php

index 12ac9c7..76c5ca7 100644 (file)
@@ -173,7 +173,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface {
                                $propertyName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToLowerCamelCase($columnName);
                        }
                        // if (in_array($propertyName, $classPropertyNames)) { // TODO Enable check for property existance
-                       $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap($columnName, $propertyName);
+                       $columnMap = $this->createColumnMap($columnName, $propertyName);
                        $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName);
                        $columnMap = $this->setRelations($columnMap, $columnDefinition['config'], $propertyMetaData);
                        $dataMap->addColumnMap($columnMap);
@@ -403,6 +403,18 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface {
                return $columnMap;
        }
 
+       /**
+        * Creates the ColumnMap object for the given columnName and propertyName
+        *
+        * @param string $columnName
+        * @param string $propertyName
+        *
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap
+        */
+       protected function createColumnMap($columnName, $propertyName) {
+               return $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', $columnName, $propertyName);
+       }
+
 }
 
 ?>
\ No newline at end of file
index ce56a21..0f58077 100644 (file)
@@ -389,6 +389,21 @@ class DataMapFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'));
                $this->assertSame($expected, $dataMapFactory->_call('resolveTableName', $className));
        }
+
+       /**
+        * @test
+        */
+       public function createColumnMapReturnsAValidColumnMap() {
+               /** @var $dataMapFactory \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory */
+               $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'));
+               $dataMapFactory->injectObjectManager($this->objectManager);
+
+               $this->assertEquals(
+                       new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('column', 'property'),
+                       $dataMapFactory->_call('createColumnMap', 'column', 'property')
+               );
+       }
+
 }
 
 ?>
\ No newline at end of file