[BUGFIX] Generation of class information fails with DateTime 57/21557/2
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Fri, 21 Jun 2013 09:34:14 +0000 (11:34 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 21 Jun 2013 10:36:34 +0000 (12:36 +0200)
If using the class info factory to create a class information
for DateTime an Exception occurs as the reflection api handles
DateTime wrong when reolving constructor arguments. Therefore a
custom class info has to be created.

Releases: 6.2
Resolves: #49307
Change-Id: Ia463776ff992eb0c91bca84710f934ee282355e5
Reviewed-on: https://review.typo3.org/21557
Reviewed-by: Stefan Froemken
Tested-by: Stefan Froemken
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Object/Container/ClassInfoFactory.php
typo3/sysext/extbase/Tests/Unit/Object/Container/ClassInfoFactoryTest.php

index e667a0c..9f5b8e7 100644 (file)
@@ -42,6 +42,9 @@ class ClassInfoFactory {
         * @return \TYPO3\CMS\Extbase\Object\Container\ClassInfo the class info
         */
        public function buildClassInfoFromClassName($className) {
+               if ($className === 'DateTime') {
+                       return new \TYPO3\CMS\Extbase\Object\Container\ClassInfo($className, array(), array(), FALSE, FALSE, array());
+               }
                try {
                        $reflectedClass = new \ReflectionClass($className);
                } catch (\Exception $e) {
index 398a7e3..ac6d1a6 100644 (file)
@@ -68,6 +68,22 @@ class ClassInfoFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $classInfo = $this->classInfoFactory->buildClassInfoFromClassName('TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithInjectProperties');
                $this->assertEquals(array('secondDummyClass' => 'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\SecondDummyClass'), $classInfo->getInjectProperties());
        }
+
+       /**
+        * @test
+        */
+       public function buildClassInfoReturnsCustomClassInfoForDateTime() {
+
+               /** @var \PHPUnit_Framework_MockObject_MockObject | \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory $classInfoFactory */
+               $classInfoFactory = $this->getMock('TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory', array('dummy'));
+               $classInfoFactory->expects($this->never())->method('getConstructorArguments');
+
+               $classInfo = $classInfoFactory->buildClassInfoFromClassName('DateTime');
+               $this->assertEquals(
+                       new \TYPO3\CMS\Extbase\Object\Container\ClassInfo('DateTime', array(), array(), FALSE, FALSE, array()),
+                       $classInfo
+               );
+       }
 }
 
 ?>
\ No newline at end of file