[TASK] Removes eval() in ArrayUtilityTest 90/40290/6
authorAlexander Krist <mail@alex-krist.de>
Tue, 16 Jun 2015 11:34:08 +0000 (13:34 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 18 Jun 2015 21:34:18 +0000 (23:34 +0200)
Adds a new ArrayUtilityMockup and removes the ugly
usage of eval() from ArrayUtitilyTest.

Change-Id: Id655f913b3eb638518cd9830e5ababc3c34b982c
Resolves: #67490
Related: #67468
Releases: master
Reviewed-on: http://review.typo3.org/40290
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php

index 09af725..12604a7 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 
 /**
@@ -22,7 +23,7 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
  * @author Susanne Moog <typo3@susanne-moog.de>
  * @author Christian Kuhn <lolli@schwarzbu.ch>
  */
-class ArrayUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class ArrayUtilityTest extends UnitTestCase {
 
        ///////////////////////
        // Tests concerning filterByValueRecursive
@@ -203,34 +204,14 @@ class ArrayUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function isValidPathReturnsTrueIfPathExists() {
-               $className = $this->getUniqueId('ArrayUtility');
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ArrayUtility {' .
-                       '  static public function getValueByPath() {' .
-                       '    return 42;' .
-                       '  }' .
-                       '}'
-               );
-               $className = __NAMESPACE__ . '\\' . $className;
-               $this->assertTrue($className::isValidPath(array('foo'), 'foo'));
+               $this->assertTrue(ArrayUtility::isValidPath(array('foo' => 'bar'), 'foo'));
        }
 
        /**
         * @test
         */
        public function isValidPathReturnsFalseIfPathDoesNotExist() {
-               $className = $this->getUniqueId('ArrayUtility');
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ArrayUtility {' .
-                       '  static public function getValueByPath() {' .
-                       '    throw new \RuntimeException(\'foo\', 123);' .
-                       '  }' .
-                       '}'
-               );
-               $className = __NAMESPACE__ . '\\' . $className;
-               $this->assertFalse($className::isValidPath(array('foo'), 'foo'));
+               $this->assertFalse(ArrayUtility::isValidPath(array('foo' => 'bar'), 'bar'));
        }
 
        ///////////////////////
@@ -1742,6 +1723,12 @@ class ArrayUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         * @dataProvider mergeRecursiveWithOverruleCalculatesExpectedResultDataProvider
+        * @param array $input1 Input 1
+        * @param array $input2 Input 2
+        * @param bool $addKeys TRUE if should add keys, else FALSE
+        * @param bool $includeEmptyValues TRUE if should include empty values, else FALSE
+        * @param bool $enableUnsetFeature TRUE if should enable unset feature, else FALSE
+        * @param array $expected expected array
         */
        public function mergeRecursiveWithOverruleCalculatesExpectedResult($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature, $expected) {
                ArrayUtility::mergeRecursiveWithOverrule($input1, $input2, $addKeys, $includeEmptyValues, $enableUnsetFeature);
@@ -1754,6 +1741,9 @@ class ArrayUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         * @dataProvider inArrayDataProvider
+        * @param array $array target array
+        * @param string $item search string
+        * @param bool $expected expected value
         */
        public function inArrayChecksStringExistenceWithinArray($array, $item, $expected) {
                $this->assertEquals($expected, ArrayUtility::inArray($array, $item));
@@ -1843,6 +1833,9 @@ class ArrayUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         * @dataProvider keepItemsInArrayWorksWithOneArgumentDataProvider
+        * @param mixed $search The items which are allowed/kept in the array
+        * @param array $array target array
+        * @param array $expected expected array
         */
        public function keepItemsInArrayWorksWithOneArgument($search, $array, $expected) {
                $this->assertEquals($expected, ArrayUtility::keepItemsInArray($array, $search));