[TASK] Remove eval() in fluid Unit Tests 02/41602/6
authorOliver Eglseder <oliver.eglseder@in2code.de>
Fri, 17 Jul 2015 20:19:16 +0000 (22:19 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 18 Jul 2015 10:04:41 +0000 (12:04 +0200)
eval() is bad and the dynamic class names are
not needed anyway

Resolves: #67666
Releases: master
Change-Id: I8e7de8126fa291e43de437df1d43a13d990070a4
Reviewed-on: http://review.typo3.org/41602
Reviewed-by: Markus Sommer <markussom@posteo.de>
Tested-by: Markus Sommer <markussom@posteo.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/fluid/Tests/Unit/Core/Compiler/AbstractCompilerTemplateTest.php
typo3/sysext/fluid/Tests/Unit/Core/Compiler/Fixtures/AbstractCompiledTemplate.php [new file with mode: 0644]
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/AbstractFormFieldViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/AbstractFormViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/ClassWithTwoGetters.php [new file with mode: 0644]
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/EmptyClass.php [new file with mode: 0644]
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/ExtendsAbstractEntity.php [new file with mode: 0644]

index ed7771d..61724a7 100644 (file)
@@ -30,15 +30,7 @@ class AbstractCompilerTemplateTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function isDefaultEncodingIsSetThanDefaultEncodingWillReturned() {
-               $className = $this->getUniqueId('AbstractCompiledTemplate');
-               $fullClassName = 'TYPO3\\CMS\\Fluid\\Core\\Compiler\\' . $className;
-               eval(
-                       'namespace TYPO3\\CMS\\Fluid\\Core\\Compiler;' .
-                               'abstract class ' . $className . ' extends AbstractCompiledTemplate {' .
-                               '  static protected $defaultEncoding = \'ISO-8859-1\';' .
-                               '}'
-               );
-               $this->assertSame('ISO-8859-1', $fullClassName::resolveDefaultEncoding());
+               $this->assertSame('ISO-8859-1', \TYPO3\CMS\Fluid\Tests\Unit\Core\Compiler\Fixtures\AbstractCompiledTemplate::resolveDefaultEncoding());
        }
 
 }
diff --git a/typo3/sysext/fluid/Tests/Unit/Core/Compiler/Fixtures/AbstractCompiledTemplate.php b/typo3/sysext/fluid/Tests/Unit/Core/Compiler/Fixtures/AbstractCompiledTemplate.php
new file mode 100644 (file)
index 0000000..70225e5
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Compiler\Fixtures;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Class AbstractCompiledTemplate
+ */
+abstract class AbstractCompiledTemplate extends \TYPO3\CMS\Fluid\Core\Compiler\AbstractCompiledTemplate {
+
+       static protected $defaultEncoding = 'ISO-8859-1';
+}
index 0b9199c..21039db 100644 (file)
@@ -23,12 +23,7 @@ class AbstractFormFieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHe
                $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
                $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnValue('6f487e40-4483-11de-8a39-0800200c9a66'));
 
-               $className = $this->getUniqueId('Object');
-               $fullClassName = 'TYPO3\\Fluid\\ViewHelpers\\Form\\' . $className;
-               eval('namespace TYPO3\\Fluid\\ViewHelpers\\Form; class ' . $className . ' {
-                       public function __clone() {}
-               }');
-               $object = $this->getMock($fullClassName);
+               $object = $this->getMock(\TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptyClass::class);
                $object->expects($this->any())->method('FLOW3_Persistence_isNew')->will($this->returnValue(FALSE));
 
                $formViewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, array('dummy'), array(), '', FALSE);
@@ -125,18 +120,7 @@ class AbstractFormFieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHe
                $formViewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, array('isObjectAccessorMode', 'addAdditionalIdentityPropertiesIfNeeded'), array(), '', FALSE);
                $this->injectDependenciesIntoViewHelper($formViewHelper);
 
-               $className = $this->getUniqueId('test_');
-               $mockObject = eval('
-                       class ' . $className . ' {
-                               public function getSomething() {
-                                       return "MyString";
-                               }
-                               public function getValue() {
-                                       return new ' . $className . ';
-                               }
-                       }
-                       return new ' . $className . ';
-               ');
+               $mockObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
 
                $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
                $formViewHelper->expects($this->once())->method('addAdditionalIdentityPropertiesIfNeeded');
@@ -250,18 +234,7 @@ class AbstractFormFieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHe
         * @test
         */
        public function addAdditionalIdentityPropertiesIfNeededCallsRenderIdentityFieldWithTheRightParameters() {
-               $className = $this->getUniqueId('test_');
-               $mockFormObject = eval('
-                       class ' . $className . ' {
-                               public function getSomething() {
-                                       return "MyString";
-                               }
-                               public function getValue() {
-                                       return new ' . $className . ';
-                               }
-                       }
-                       return new ' . $className . ';
-               ');
+               $mockFormObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
                $property = 'value.something';
                $objectName = 'myObject';
                $expectedProperty = 'myObject[value]';
@@ -283,18 +256,7 @@ class AbstractFormFieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHe
         * @test
         */
        public function addAdditionalIdentityPropertiesIfNeededCallsRenderIdentityFieldWithTheRightParametersWithMoreHierarchyLevels() {
-               $className = $this->getUniqueId('test_');
-               $mockFormObject = eval('
-                       class ' . $className . ' {
-                               public function getSomething() {
-                                       return "MyString";
-                               }
-                               public function getValue() {
-                                       return new ' . $className . ';
-                               }
-                       }
-                       return new ' . $className . ';
-               ');
+               $mockFormObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
                $property = 'value.value.something';
                $objectName = 'myObject';
                $expectedProperty1 = 'myObject[value]';
index 34e0ecf..5155485 100644 (file)
@@ -30,11 +30,7 @@ class AbstractFormViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers
         * @test
         */
        public function renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUID() {
-               $className = $this->getUniqueId('Object');
-               $fullClassName = '\\TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\' . $className;
-               eval('namespace TYPO3\\CMS\\Fluid\\ViewHelpers\\Form; class ' . $className . ' extends \\' . \TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class . ' {
-               }');
-               $object = $this->getAccessibleMock($fullClassName, array('dummy'));
+               $object = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ExtendsAbstractEntity::class, array('dummy'));
                $object->_set('uid', 123);
                $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
                $viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, array('prefixFieldName', 'registerFieldNameForFormTokenGeneration'), array(), '', FALSE);
@@ -47,10 +43,7 @@ class AbstractFormViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers
         * @test
         */
        public function renderHiddenIdentityFieldReturnsAHiddenInputFieldIfObjectIsNewButAClone() {
-               $className = $this->getUniqueId('Object');
-               eval('class ' . $className . ' extends TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
-               }');
-               $object = $this->getAccessibleMock($className, array('dummy'));
+               $object = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ExtendsAbstractEntity::class, array('dummy'));
                $object->_set('uid', 123);
                $object = clone $object;
                $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/ClassWithTwoGetters.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/ClassWithTwoGetters.php
new file mode 100644 (file)
index 0000000..76eb702
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Class ClassWithTwoGetters
+ */
+class ClassWithTwoGetters {
+
+       /**
+        * @return string
+        */
+       public function getSomething() {
+               return 'MyString';
+       }
+
+       /**
+        * @return mixed
+        */
+       public function getValue() {
+               return new ClassWithTwoGetters();
+       }
+}
diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/EmptyClass.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/EmptyClass.php
new file mode 100644 (file)
index 0000000..732eee7
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Class EmptyClass
+ */
+class EmptyClass {
+
+}
diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/ExtendsAbstractEntity.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/Fixtures/ExtendsAbstractEntity.php
new file mode 100644 (file)
index 0000000..4f901d9
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Class ExtendsAbstractEntity
+ */
+class ExtendsAbstractEntity extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
+
+}