[TASK] Removes eval() in core version number utility unit tests 31/40431/3
authorPierrick Caillon <pierrick.caillon@plan-net.fr>
Thu, 18 Jun 2015 10:16:00 +0000 (12:16 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 18 Jun 2015 20:18:28 +0000 (22:18 +0200)
Adds fixture for specifying current version in VersionNumberUtility
and removes the ugly usage of eval() from VersionNumberUtilityTest.

Resolves: #67594
Related: #67468
Releases: master
Change-Id: Ia4b256c1a1e61dc117519c243d0e465fb36e8662
Reviewed-on: http://review.typo3.org/40431
Reviewed-by: Alexander Krist <mail@alex-krist.de>
Tested-by: Alexander Krist <mail@alex-krist.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Tests/Unit/Utility/Fixtures/VersionNumberUtilityFixture.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Utility/VersionNumberUtilityTest.php

diff --git a/typo3/sysext/core/Tests/Unit/Utility/Fixtures/VersionNumberUtilityFixture.php b/typo3/sysext/core/Tests/Unit/Utility/Fixtures/VersionNumberUtilityFixture.php
new file mode 100644 (file)
index 0000000..306c869
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Utility\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\Core\Utility\VersionNumberUtility;
+
+/**
+ * Fixture overwriting current version
+ */
+class VersionNumberUtilityFixture extends VersionNumberUtility {
+       public static $versionNumber;
+
+       static public function getCurrentTypo3Version() {
+               return self::$versionNumber;
+       }
+}
index 298ace8..16cc081 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\Unit\Utility\Fixtures\VersionNumberUtilityFixture;
 use TYPO3\CMS\Core\Utility\VersionNumberUtility;
 
 /**
@@ -127,17 +128,8 @@ class VersionNumberUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @param string $expectedVersion
         */
        public function getNumericTypo3VersionNumber($currentVersion, $expectedVersion) {
-               $className = $this->getUniqueId('VersionNumberUtility');
-               eval(
-                       'namespace ' . __NAMESPACE__ . ';' .
-                       'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\VersionNumberUtility {' .
-                       '  static public function getCurrentTypo3Version() {' .
-                       '    return \'' . $currentVersion . '\';' .
-                       '  }' .
-                       '}'
-               );
-               $className = __NAMESPACE__ . '\\' . $className;
-               $this->assertEquals($expectedVersion, $className::getNumericTypo3Version());
+               VersionNumberUtilityFixture::$versionNumber = $currentVersion;
+               $this->assertEquals($expectedVersion, VersionNumberUtilityFixture::getNumericTypo3Version());
        }
 
        /**