[TASK] Removes eval() in core tree data provider factory unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Tree / TableConfiguration / TreeDataProviderFactoryTest.php
index ea2d37e..60fff05 100644 (file)
@@ -1,31 +1,19 @@
 <?php
 namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration;
 
-/***************************************************************
- *  Copyright notice
+/*
+ * This file is part of the TYPO3 CMS project.
  *
- *  (c) 2012-2013 Helmut Hummel <helmut.hummel@typo3.org>
- *  All rights reserved
+ * 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.
  *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
+use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderFixture;
 
 /**
  * Testcase for TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
@@ -35,10 +23,10 @@ class TreeDataProviderFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @var \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
         */
-       protected $fixture;
+       protected $subject;
 
-       public function setUp() {
-               $this->fixture = new \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory();
+       protected function setUp() {
+               $this->subject = new \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory();
                $GLOBALS['TCA'] = array();
                $GLOBALS['TCA']['foo'] = array();
                $GLOBALS['TCA']['foo']['ctrl'] = array();
@@ -88,21 +76,17 @@ class TreeDataProviderFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @expectedException \InvalidArgumentException
         */
        public function factoryThrowsExceptionIfInvalidConfigurationIsGiven(array $tcaConfiguration) {
-               $this->fixture->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
+               $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
        }
 
        /**
         * @test
         */
        public function configuredDataProviderClassIsInstantiated() {
-               $dataProviderMockClassName = uniqid('tx_coretest_tree_data_provider');
-               eval('class ' . $dataProviderMockClassName . ' {
-                       function __construct($configuration) {
-                       }
-               }');
+               $dataProviderMockClassName = TreeDataProviderFixture::class;
 
                $tcaConfiguration = array('treeConfig' => array('dataProvider' => $dataProviderMockClassName), 'internal_type' => 'foo');
-               $dataProvider = $this->fixture->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
+               $dataProvider = $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
 
                $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
        }
@@ -111,17 +95,18 @@ class TreeDataProviderFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor() {
-               $dataProviderMockClassName = uniqid('tx_coretest_tree_data_provider');
+               $dataProviderMockClassName = $this->getUniqueId('tx_coretest_tree_data_provider');
                $tcaConfiguration = array('treeConfig' => array('dataProvider' => $dataProviderMockClassName), 'internal_type' => 'foo');
                $classCode = 'class ' . $dataProviderMockClassName . ' {
                        function __construct($configuration) {
-                               if (!is_array($configuration)) throw new Exception(\'Failed asserting that the contructor arguments are an array\');
-                               if ($configuration !== ' . var_export($tcaConfiguration, TRUE) . ') throw new Exception(\'Failed asserting that the contructor arguments are correctly passed\');
+                               if (!is_array($configuration)) throw new Exception(\'Failed asserting that the constructor arguments are an array\');
+                               if ($configuration !== ' . var_export($tcaConfiguration, TRUE) . ') throw new Exception(\'Failed asserting that the constructor arguments are correctly passed\');
                        }
                }';
                eval($classCode);
-               $dataProvider = $this->fixture->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
+               $dataProvider = $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
 
                $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
        }
+
 }