[TASK] Add additional configuration for functional tests 73/27773/4
authorHelmut Hummel <helmut.hummel@typo3.org>
Fri, 21 Feb 2014 14:22:13 +0000 (15:22 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 22 Feb 2014 14:38:23 +0000 (15:38 +0100)
Our functional test suit does not fail currently when
tested code emits a PHP warning. This is due to the
fact that the factory configuration uses the
production exception handler which silently discards
warnings.

This change adds additional configuration that
is merged with the factory configuration.

In this configuration the TYPO3 exception handling
is disabled and the core and classes cache is
disabled.

Additionally a new property is added to the base
class to easily add some configuration values that
might be needed for the test case.

Resolves: #56187
Related: #56086
Releases: 6.2
Change-Id: I5c7c2c0d495bae06a56d2285b8d521eaa4ab37d2
Reviewed-on: https://review.typo3.org/27773
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Build/Configuration/FunctionalTestsConfiguration.php [new file with mode: 0644]
typo3/sysext/core/Tests/FunctionalTestCase.php
typo3/sysext/core/Tests/FunctionalTestCaseBootstrapUtility.php

diff --git a/typo3/sysext/core/Build/Configuration/FunctionalTestsConfiguration.php b/typo3/sysext/core/Build/Configuration/FunctionalTestsConfiguration.php
new file mode 100644 (file)
index 0000000..da25c98
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+return array(
+       'SYS' => array(
+               'displayErrors' => '1',
+               'debugExceptionHandler' => '',
+               'caching' => array(
+                       'cacheConfigurations' => array(
+                               'cache_core' => array(
+                                       'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\NullBackend'
+                               ),
+                               'cache_classes' => array(
+                                       'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\TransientMemoryBackend'
+                               ),
+                       )
+               )
+       )
+);
index f816242..5d52635 100644 (file)
@@ -57,7 +57,6 @@ use \TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Response;
  *     typo3/sysext/core/Tests/Functional/DataHandling/DataHandlerTest.php
  */
 abstract class FunctionalTestCase extends BaseTestCase {
-
        /**
         * Core extensions to load.
         *
@@ -130,6 +129,14 @@ abstract class FunctionalTestCase extends BaseTestCase {
        protected $pathsToLinkInTestInstance = array();
 
        /**
+        * This configuration array is merged with TYPO3_CONF_VARS
+        * that are set in default configuration and factory configuration
+        *
+        * @var array
+        */
+       protected $configurationToUseInTestInstance = array();
+
+       /**
         * Private utility class used in setUp() and tearDown(). Do NOT use in test cases!
         *
         * @var \TYPO3\CMS\Core\Tests\FunctionalTestCaseBootstrapUtility
@@ -159,7 +166,8 @@ abstract class FunctionalTestCase extends BaseTestCase {
                        get_class($this),
                        $this->coreExtensionsToLoad,
                        $this->testExtensionsToLoad,
-                       $this->pathsToLinkInTestInstance
+                       $this->pathsToLinkInTestInstance,
+                       $this->configurationToUseInTestInstance
                );
        }
 
index 0af5224..5ca1dc2 100644 (file)
@@ -75,13 +75,15 @@ class FunctionalTestCaseBootstrapUtility {
         * @param array $coreExtensionsToLoad Array of core extensions to load
         * @param array $testExtensionsToLoad Array of test extensions to load
         * @param array $pathsToLinkInTestInstance Array of source => destination path pairs to be linked
+        * @param array $configurationToUse Array of TYPO3_CONF_VARS that need to be overridden
         * @return string Path to TYPO3 CMS test installation for this test case
         */
        public function setUp(
                $testCaseClassName,
                array $coreExtensionsToLoad,
                array $testExtensionsToLoad,
-               array $pathsToLinkInTestInstance
+               array $pathsToLinkInTestInstance,
+               array $configurationToUse
        ) {
                $this->setUpIdentifier($testCaseClassName);
                $this->setUpInstancePath();
@@ -90,7 +92,7 @@ class FunctionalTestCaseBootstrapUtility {
                $this->setUpInstanceCoreLinks();
                $this->linkTestExtensionsToInstance($testExtensionsToLoad);
                $this->linkPathsInTestInstance($pathsToLinkInTestInstance);
-               $this->setUpLocalConfiguration();
+               $this->setUpLocalConfiguration($configurationToUse);
                $this->setUpPackageStates($coreExtensionsToLoad, $testExtensionsToLoad);
                $this->setUpBasicTypo3Bootstrap();
                $this->setUpTestDatabase();
@@ -260,14 +262,17 @@ class FunctionalTestCaseBootstrapUtility {
        /**
         * Create LocalConfiguration.php file in the test instance
         *
+        * @param array $configurationToMerge
         * @throws Exception
         * @return void
         */
-       protected function setUpLocalConfiguration() {
+       protected function setUpLocalConfiguration(array $configurationToMerge) {
                $originalConfigurationArray = require ORIGINAL_ROOT . 'typo3conf/LocalConfiguration.php';
                // Base of final LocalConfiguration is core factory configuration
                $finalConfigurationArray = require ORIGINAL_ROOT .'typo3/sysext/core/Configuration/FactoryConfiguration.php';
 
+               $this->mergeRecursiveWithOverrule($finalConfigurationArray, require ORIGINAL_ROOT .'typo3/sysext/core/Build/Configuration/FunctionalTestsConfiguration.php');
+               $this->mergeRecursiveWithOverrule($finalConfigurationArray, $configurationToMerge);
                $finalConfigurationArray['DB'] = $originalConfigurationArray['DB'];
                // Calculate and set new database name
                $this->originalDatabaseName = $originalConfigurationArray['DB']['database'];
@@ -343,13 +348,13 @@ class FunctionalTestCaseBootstrapUtility {
 
                // Activate test extensions that have been symlinked before
                foreach ($testExtensionPaths as $extensionPath) {
+                       $extensionName = basename($extensionPath);
                        if (isset($packageSates['packages'][$extensionName])) {
                                throw new Exception(
                                        $extensionName . ' is already registered as extension to load, no need to load it explicitly',
                                        1390913894
                                );
                        }
-                       $extensionName = basename($extensionPath);
                        $packageStates['packages'][$extensionName] = array(
                                'state' => 'active',
                                'packagePath' => 'typo3conf/ext/' . $extensionName . '/',
@@ -623,4 +628,47 @@ class FunctionalTestCaseBootstrapUtility {
                $lines .= str_repeat(chr(9), ($level - 1)) . ')' . ($level - 1 == 0 ? '' : ',' . chr(10));
                return $lines;
        }
+
+       /**
+        * COPIED FROM ArrayUtility
+        *
+        * Merges two arrays recursively and "binary safe" (integer keys are
+        * overridden as well), overruling similar values in the original array
+        * with the values of the overrule array.
+        * In case of identical keys, ie. keeping the values of the overrule array.
+        *
+        * This method takes the original array by reference for speed optimization with large arrays
+        *
+        * The differences to the existing PHP function array_merge_recursive() are:
+        *  * Keys of the original array can be unset via the overrule array. ($enableUnsetFeature)
+        *  * Much more control over what is actually merged. ($addKeys, $includeEmptyValues)
+        *  * Elements or the original array get overwritten if the same key is present in the overrule array.
+        *
+        * @param array $original Original array. It will be *modified* by this method and contains the result afterwards!
+        * @param array $overrule Overrule array, overruling the original array
+        * @param boolean $addKeys If set to FALSE, keys that are NOT found in $original will not be set. Thus only existing value can/will be overruled from overrule array.
+        * @param boolean $includeEmptyValues If set, values from $overrule will overrule if they are empty or zero.
+        * @param boolean $enableUnsetFeature If set, special values "__UNSET" can be used in the overrule array in order to unset array keys in the original array.
+        * @return void
+        */
+       protected function mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys = TRUE, $includeEmptyValues = TRUE, $enableUnsetFeature = TRUE) {
+               foreach (array_keys($overrule) as $key) {
+                       if ($enableUnsetFeature && $overrule[$key] === '__UNSET') {
+                               unset($original[$key]);
+                               continue;
+                       }
+                       if (isset($original[$key]) && is_array($original[$key])) {
+                               if (is_array($overrule[$key])) {
+                                       self::mergeRecursiveWithOverrule($original[$key], $overrule[$key], $addKeys, $includeEmptyValues, $enableUnsetFeature);
+                               }
+                       } elseif (
+                               ($addKeys || isset($original[$key])) &&
+                               ($includeEmptyValues || $overrule[$key])
+                       ) {
+                               $original[$key] = $overrule[$key];
+                       }
+               }
+               // This line is kept for backward compatibility reasons.
+               reset($original);
+       }
 }