[TASK] Removes eval() in core tree dataprovider unit test 21/42321/3
authorMarkus Guenther <mail@markus-guenther.de>
Thu, 6 Aug 2015 14:21:23 +0000 (16:21 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 6 Aug 2015 16:00:29 +0000 (18:00 +0200)
Adds fixture for TreeDataProviderWithConfigurationFixture and removes the
ugly usage of eval() from TreeDataProviderFactoryTest in unit tests.

Change-Id: I32c98ba353a0cc85488325f112ab2d67c7cfae1e
Resolves: #67667
Related: #67468
Releases: master
Reviewed-on: http://review.typo3.org/42321
Reviewed-by: Sascha Wilking <sascha.wilking@hmmh.de>
Tested-by: Sascha Wilking <sascha.wilking@hmmh.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/Fixtures/TreeDataProviderWithConfigurationFixture.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/TreeDataProviderFactoryTest.php

diff --git a/typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/Fixtures/TreeDataProviderWithConfigurationFixture.php b/typo3/sysext/core/Tests/Unit/Tree/TableConfiguration/Fixtures/TreeDataProviderWithConfigurationFixture.php
new file mode 100644 (file)
index 0000000..315c5a7
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\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 configured data provider
+ */
+class TreeDataProviderWithConfigurationFixture {
+
+       /**
+        * @param array $configuration
+        * @throws \Exception
+        */
+       public function __construct($configuration) {
+               if (!is_array($configuration)) {
+                       throw new \Exception('Failed asserting that the constructor arguments are an array', 1438875247);
+               }
+               $tcaConfiguration = [
+                       'treeConfig' => [
+                               'dataProvider' => TreeDataProviderWithConfigurationFixture::class,
+                       ],
+                       'internal_type' => 'foo',
+               ];
+               if ($configuration !== $tcaConfiguration) {
+                       throw new \Exception('Failed asserting that the constructor arguments are correctly passed', 1438875248);
+               }
+               throw new  \RuntimeException('This must be thrown', 1438875249);
+       }
+
+}
index 60fff05..1563d90 100644 (file)
@@ -13,20 +13,24 @@ namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderFixture;
+use TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration\Fixtures\TreeDataProviderWithConfigurationFixture;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+use TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory;
 
 /**
- * Testcase for TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
+ * Test case
  */
-class TreeDataProviderFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class TreeDataProviderFactoryTest extends UnitTestCase {
 
        /**
-        * @var \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory
+        * @var TreeDataProviderFactory
         */
        protected $subject;
 
        protected function setUp() {
-               $this->subject = new \TYPO3\CMS\Core\Tree\TableConfiguration\TreeDataProviderFactory();
+               $this->subject = new TreeDataProviderFactory();
                $GLOBALS['TCA'] = array();
                $GLOBALS['TCA']['foo'] = array();
                $GLOBALS['TCA']['foo']['ctrl'] = array();
@@ -95,18 +99,16 @@ class TreeDataProviderFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function configuredDataProviderClassIsInstantiatedWithTcaConfigurationInConstructor() {
-               $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 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->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
+               $dataProviderMockClassName = TreeDataProviderWithConfigurationFixture::class;
 
-               $this->assertInstanceOf($dataProviderMockClassName, $dataProvider);
+               $tcaConfiguration = [
+                       'treeConfig' => [
+                               'dataProvider' => $dataProviderMockClassName,
+                       ],
+                       'internal_type' => 'foo',
+               ];
+               $this->setExpectedException(\RuntimeException::class, $this->anything(), 1438875249);
+               $this->subject->getDataProvider($tcaConfiguration, 'foo', 'bar', array('uid' => 1));
        }
 
 }