[TASK] Removes eval() in extbase unit tests for TypeConverter 26/42326/3
authorMarkus Guenther <mail@markus-guenther.de>
Thu, 6 Aug 2015 16:29:54 +0000 (18:29 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 6 Aug 2015 17:17:05 +0000 (19:17 +0200)
Add fixtures for the DateTimeConverterTest, PersistentObjectConverterTest and the
PropertyMapperTest.

Change-Id: I6dc1214ea1eab6a566f1881f0f0dd3d209af261b
Resolves: #68803
Related: #67665
Releases: master
Reviewed-on: http://review.typo3.org/42326
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
13 files changed:
typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderOne.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderOneInterface.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderThree.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderThreeInterface.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderTwo.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderTwoInterface.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/PropertyMapperTest.php
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/DateTimeConverterTest.php
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/DateTimeSubFixture.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectEntityFixture.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectFixture.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectValueObjectFixture.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php

diff --git a/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderOne.php b/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderOne.php
new file mode 100644 (file)
index 0000000..b8a7fc6
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\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!
+ */
+
+/**
+ * Fixture DataProviderOne
+ */
+class DataProviderOne implements DataProviderOneInterface{}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderOneInterface.php b/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderOneInterface.php
new file mode 100644 (file)
index 0000000..db95620
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\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!
+ */
+
+/**
+ * Fixture DataProviderOneInterface
+ */
+interface DataProviderOneInterface {}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderThree.php b/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderThree.php
new file mode 100644 (file)
index 0000000..2d0063f
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\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!
+ */
+
+/**
+ * Fixture DataProviderThree
+ */
+class DataProviderThree extends DataProviderTwo implements DataProviderThreeInterface {}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderThreeInterface.php b/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderThreeInterface.php
new file mode 100644 (file)
index 0000000..535d51c
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\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!
+ */
+
+/**
+ * Fixture DataProviderThreeInterface
+ */
+interface DataProviderThreeInterface extends DataProviderTwoInterface {}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderTwo.php b/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderTwo.php
new file mode 100644 (file)
index 0000000..1e69444
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\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!
+ */
+
+/**
+ * Fixture DataProviderTwo
+ */
+class DataProviderTwo extends DataProviderOne {}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderTwoInterface.php b/typo3/sysext/extbase/Tests/Unit/Property/Fixtures/DataProviderTwoInterface.php
new file mode 100644 (file)
index 0000000..314720f
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\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!
+ */
+
+/**
+ * Fixture DataProviderTwoInterface
+ */
+interface DataProviderTwoInterface {}
\ No newline at end of file
index 9ca62f9..56c5e05 100644 (file)
@@ -21,6 +21,13 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Property;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Extbase\Tests\Unit\Property\Fixtures\DataProviderOne;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\Fixtures\DataProviderOneInterface;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\Fixtures\DataProviderThree;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\Fixtures\DataProviderThreeInterface;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\Fixtures\DataProviderTwo;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\Fixtures\DataProviderTwoInterface;
+
 /**
  * Test case
  */
 /**
  * Test case
  */
@@ -178,24 +185,12 @@ class PropertyMapperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function dataProviderForObjectTypeConverters() {
                $data = array();
 
        public function dataProviderForObjectTypeConverters() {
                $data = array();
 
-               $className1 = $this->getUniqueId('TYPO3_Flow_Testclass1_', FALSE);
-               $className2 = $this->getUniqueId('TYPO3_Flow_Testclass2_', FALSE);
-               $className3 = $this->getUniqueId('TYPO3_Flow_Testclass3_', FALSE);
-
-               $interfaceName1 = $this->getUniqueId('TYPO3_Flow_TestInterface1_', FALSE);
-               $interfaceName2 = $this->getUniqueId('TYPO3_Flow_TestInterface2_', FALSE);
-               $interfaceName3 = $this->getUniqueId('TYPO3_Flow_TestInterface3_', FALSE);
-
-               eval("
-                       interface $interfaceName2 {}
-                       interface $interfaceName1 {}
-
-                       interface $interfaceName3 extends $interfaceName2 {}
+               $className2 = DataProviderTwo::class;
+               $className3 = DataProviderThree::class;
 
 
-                       class $className1 implements $interfaceName1 {}
-                       class $className2 extends $className1 {}
-                       class $className3 extends $className2 implements $interfaceName3 {}
-               ");
+               $interfaceName1 = DataProviderOneInterface::class;
+               $interfaceName2 = DataProviderTwoInterface::class;
+               $interfaceName3 = DataProviderThreeInterface::class;
 
                // The most specific converter should win
                $data[] = array(
 
                // The most specific converter should win
                $data[] = array(
index 09db0fa..dc16d4a 100644 (file)
@@ -21,6 +21,8 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\Fixtures\DateTimeSubFixture;
+
 /**
  * Test case
  */
 /**
  * Test case
  */
@@ -390,15 +392,7 @@ class DateTimeConverterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function convertFromSupportsDateTimeSubClasses() {
         * @test
         */
        public function convertFromSupportsDateTimeSubClasses() {
-               $className = $this->getUniqueId('DateTimeSubClass');
-               eval('
-                       class ' . $className . ' extends \\DateTime {
-                               static public function createFromFormat($format, $time, $timezone = NULL) {
-                                       return new ' . $className . '();
-                               }
-                               public function foo() { return "Bar"; }
-                       }
-               ');
+               $className = DateTimeSubFixture::class;
                $date = $this->converter->convertFrom('2005-08-15T15:52:01+00:00', $className);
 
                $this->assertInstanceOf($className, $date);
                $date = $this->converter->convertFrom('2005-08-15T15:52:01+00:00', $className);
 
                $this->assertInstanceOf($className, $date);
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/DateTimeSubFixture.php b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/DateTimeSubFixture.php
new file mode 100644 (file)
index 0000000..b3e16b3
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\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!
+ */
+
+/**
+ * Fixture date time sub
+ */
+class DateTimeSubFixture extends \DateTime {
+
+       /**
+        * @param string $format
+        * @param string $time
+        * @param \DateTimeZone $timezone
+        * @return DateTimeSubFixture
+        */
+       static public function createFromFormat($format, $time, \DateTimeZone $timezone = NULL) {
+               return new DateTimeSubFixture();
+       }
+
+       /**
+        * @return string
+        */
+       public function foo() {
+               return 'Bar';
+       }
+}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectEntityFixture.php b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectEntityFixture.php
new file mode 100644 (file)
index 0000000..2c413ea
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\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!
+ */
+
+use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
+
+/**
+ * Fixture PersistentObjectEntityFixture
+ */
+class PersistentObjectEntityFixture extends AbstractEntity {}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectFixture.php b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectFixture.php
new file mode 100644 (file)
index 0000000..38cc795
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\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!
+ */
+
+/**
+ * Fixture PersistentObjectFixture
+ */
+class PersistentObjectFixture {}
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectValueObjectFixture.php b/typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/Fixtures/PersistentObjectValueObjectFixture.php
new file mode 100644 (file)
index 0000000..8468c1c
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\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!
+ */
+
+use TYPO3\CMS\Extbase\DomainObject\AbstractValueObject;
+
+/**
+ * Fixture PersistentObjectValueObjectFixture
+ */
+class PersistentObjectValueObjectFixture extends AbstractValueObject {}
\ No newline at end of file
index 6a74a21..e6265f3 100644 (file)
@@ -22,6 +22,9 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter;
  *                                                                        */
 use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter;
  *                                                                        */
 use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\Fixtures\PersistentObjectEntityFixture;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\Fixtures\PersistentObjectFixture;
+use TYPO3\CMS\Extbase\Tests\Unit\Property\TypeConverter\Fixtures\PersistentObjectValueObjectFixture;
 
 /**
  * Test case
 
 /**
  * Test case
@@ -112,13 +115,12 @@ class PersistentObjectConverterTest extends UnitTestCase {
         * @dataProvider dataProviderForCanConvert
         */
        public function canConvertFromReturnsTrueIfClassIsTaggedWithEntityOrValueObject($isEntity, $isValueObject, $expected) {
         * @dataProvider dataProviderForCanConvert
         */
        public function canConvertFromReturnsTrueIfClassIsTaggedWithEntityOrValueObject($isEntity, $isValueObject, $expected) {
-               $className = $this->getUniqueId('Test_Class');
+               $className = PersistentObjectFixture::class;
+
                if ($isEntity) {
                if ($isEntity) {
-                       eval("class {$className} extends \\" . \TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class . " {}");
+                       $className = PersistentObjectEntityFixture::class;
                } elseif ($isValueObject) {
                } elseif ($isValueObject) {
-                       eval("class {$className} extends \\" . \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject::class . " {}");
-               } else {
-                       eval("class {$className} {}");
+                       $className = PersistentObjectValueObjectFixture::class;
                }
                $this->assertEquals($expected, $this->converter->canConvertFrom('myInputData', $className));
        }
                }
                $this->assertEquals($expected, $this->converter->canConvertFrom('myInputData', $className));
        }