From ca9c89c276557ddfba0bc144029c6c57db180de6 Mon Sep 17 00:00:00 2001 From: Christian Kuhn <lolli@schwarzbu.ch> Date: Tue, 18 Mar 2014 13:28:36 +0100 Subject: [PATCH] [BUGFIX] Do not load LocalConfiguration in unit test bootstrap The patch removes loadConfigurationAndInitialize() from unit test bootstrap and substitutes it with some more fine grained bootstrap calls. In effect, the instance specific LocalConfiguration.php is no longer loaded and removes another depencency from unit tests to the instance. Change-Id: Ia6591fe8d40d530558a514832c8d649c46b4ccc9 Resolves: #57035 Related: #51436 Releases: 6.2 Reviewed-on: https://review.typo3.org/28491 Reviewed-by: Helmut Hummel Tested-by: Helmut Hummel Reviewed-by: Markus Klein Tested-by: Markus Klein --- .../sysext/core/Build/UnitTestsBootstrap.php | 22 +++++++++++++------ typo3/sysext/core/Classes/Core/Bootstrap.php | 12 ++++++---- .../Configuration/DefaultConfiguration.php | 1 + .../Tests/Unit/Utility/GeneralUtilityTest.php | 3 ++- .../Security/Cryptography/HashServiceTest.php | 4 ++++ 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/typo3/sysext/core/Build/UnitTestsBootstrap.php b/typo3/sysext/core/Build/UnitTestsBootstrap.php index 71383c8425c0..ef74bd6298de 100644 --- a/typo3/sysext/core/Build/UnitTestsBootstrap.php +++ b/typo3/sysext/core/Build/UnitTestsBootstrap.php @@ -91,14 +91,22 @@ unset($webRoot); define('PATH_thisScript', PATH_site . 'typo3/cli_dispatch.phpsh'); $_SERVER['SCRIPT_NAME'] = PATH_thisScript; -/** - * Basic bootstrap - * Can be simplified/ stripped down once the according tests are properly mocked - */ +putenv('TYPO3_CONTEXT=Testing'); + require PATH_site . '/typo3/sysext/core/Classes/Core/Bootstrap.php'; + \TYPO3\CMS\Core\Core\Bootstrap::getInstance() ->baseSetup() - ->loadConfigurationAndInitialize(TRUE); + ->initializeClassLoader(); + +$configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager(); +$GLOBALS['TYPO3_CONF_VARS'] = $configurationManager->getDefaultConfiguration(); + +\TYPO3\CMS\Core\Core\Bootstrap::getInstance() + ->disableCoreAndClassesCache() + ->initializeCachingFramework() + ->initializeClassLoaderCaches() + ->initializePackageManagement('TYPO3\\CMS\\Core\\Package\\PackageManager'); -// Load ext_localconf of phpunit. It takes care of registering phpunit classes and dependencies like vfsStream -require PATH_site . '/typo3conf/ext/phpunit/ext_localconf.php'; \ No newline at end of file +require PATH_site . 'typo3conf/ext/phpunit/Composer/vendor/autoload.php'; +require PATH_site . 'typo3conf/ext/phpunit/Migrations/vfsStream.php'; diff --git a/typo3/sysext/core/Classes/Core/Bootstrap.php b/typo3/sysext/core/Classes/Core/Bootstrap.php index 184507377102..393809877031 100644 --- a/typo3/sysext/core/Classes/Core/Bootstrap.php +++ b/typo3/sysext/core/Classes/Core/Bootstrap.php @@ -255,8 +255,9 @@ class Bootstrap { * Initializes the Class Loader * * @return Bootstrap + * @internal This is not a public API method, do not use in own extensions */ - protected function initializeClassLoader() { + public function initializeClassLoader() { $classLoader = new ClassLoader($this->applicationContext); $this->setEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassLoader', $classLoader); $classLoader->setRuntimeClassLoadingInformationFromAutoloadRegistry((array) include __DIR__ . '/../../ext_autoload.php'); @@ -292,8 +293,9 @@ class Bootstrap { * Initialize class loader cache. * * @return Bootstrap + * @internal This is not a public API method, do not use in own extensions */ - protected function initializeClassLoaderCaches() { + public function initializeClassLoaderCaches() { /** @var $classLoader ClassLoader */ $classLoader = $this->getEarlyInstance('TYPO3\\CMS\\Core\\Core\\ClassLoader'); $classLoader->injectCoreCache($this->getEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_core')); @@ -307,8 +309,9 @@ class Bootstrap { * * @param string $packageManagerClassName Define an alternative package manager implementation (usually for the installer) * @return Bootstrap + * @internal This is not a public API method, do not use in own extensions */ - protected function initializePackageManagement($packageManagerClassName) { + public function initializePackageManagement($packageManagerClassName) { /** @var \TYPO3\CMS\Core\Package\PackageManager $packageManager */ $packageManager = new $packageManagerClassName(); $this->setEarlyInstance('TYPO3\\Flow\\Package\\PackageManager', $packageManager); @@ -467,8 +470,9 @@ class Bootstrap { * Initialize caching framework * * @return Bootstrap + * @internal This is not a public API method, do not use in own extensions */ - protected function initializeCachingFramework() { + public function initializeCachingFramework() { $this->setEarlyInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework()); // @deprecated since 6.2 will be removed in two versions $GLOBALS['typo3CacheManager'] = new \TYPO3\CMS\Core\Compatibility\GlobalObjectDeprecationDecorator('TYPO3\\CMS\\Core\\Cache\\CacheManager'); diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php index 05bc41f32776..74e01d197129 100644 --- a/typo3/sysext/core/Configuration/DefaultConfiguration.php +++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php @@ -764,6 +764,7 @@ return array( 'hidePagesIfNotTranslatedByDefault' => FALSE, // Boolean: If TRUE, pages that has no translation will be hidden by default. Basically this will inverse the effect of the page localization setting "Hide page if no translation for current language exists" to "Show page even if no translation exists" 'eID_include' => array(), // Array of key/value pairs where key is "tx_[ext]_[optional suffix]" and value is relative filename of class to include. Key is used as "?eID=" for index_ts.php to include the code file which renders the page from that point. (Useful for functionality that requires a low initialization footprint, eg. frontend ajax applications) 'disableNoCacheParameter' => FALSE, // Boolean: If set, the no_cache request parameter will become ineffective. This is currently still an experimental feature and will require a website only with plugins that don't use this parameter. However, using "&no_cache=1" should be avoided anyway because there are better ways to disable caching for a certain part of the website (see COA_INT/USER_INT documentation in TSref). + 'cacheHash' => array(), // Array: Processed values of the cHash* parameters, handled by core bootstrap internally 'cHashExcludedParameters' => 'L', // String: The the given parameters will be ignored in the cHash calculation. Example: L,tx_search_pi1[query] 'cHashOnlyForParameters' => '', // String: Only the given parameters will be evaluated in the cHash calculation. Example: tx_news_pi1[uid] 'cHashRequiredParameters' => '', // Optional: Configure Parameters that require a cHash. If no cHash is given but one of the parameters are set, then TYPO3 triggers the configured cHash Error behaviour diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 19963324c12f..c92ff3026ea5 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -4141,6 +4141,7 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { /////////////////////////////////////////////////// // Tests concerning callUserFunction /////////////////////////////////////////////////// + /** * @test * @dataProvider callUserFunctionInvalidParameterDataprovider @@ -4149,7 +4150,7 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $inputData = array('foo' => 'bar'); // omit the debug() output ob_start(); - $result = Utility\GeneralUtility::callUserFunction($functionName, $inputData, $this, 'user_'); + $result = Utility\GeneralUtility::callUserFunction($functionName, $inputData, $this, 'user_', 1); ob_end_clean(); $this->assertFalse($result); } diff --git a/typo3/sysext/extbase/Tests/Unit/Security/Cryptography/HashServiceTest.php b/typo3/sysext/extbase/Tests/Unit/Security/Cryptography/HashServiceTest.php index daa51a60e91c..281d83af8e8f 100644 --- a/typo3/sysext/extbase/Tests/Unit/Security/Cryptography/HashServiceTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Security/Cryptography/HashServiceTest.php @@ -29,10 +29,14 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Security\Cryptography; */ class HashServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { + /** + * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService + */ protected $hashService; public function setUp() { $this->hashService = new \TYPO3\CMS\Extbase\Security\Cryptography\HashService(); + $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 'Testing'; } /** -- GitLab