diff options
-rw-r--r-- | core/Config.php | 40 | ||||
-rw-r--r-- | plugins/TestRunner/Commands/TestsSetupFixture.php | 6 | ||||
-rw-r--r-- | tests/PHPUnit/Framework/Mock/TestConfig.php | 52 |
3 files changed, 31 insertions, 67 deletions
diff --git a/core/Config.php b/core/Config.php index 02deddc016..0d25eb19ac 100644 --- a/core/Config.php +++ b/core/Config.php @@ -91,46 +91,6 @@ class Config extends Singleton } /** - * Enable test environment - * - * @param string $pathLocal - * @param string $pathGlobal - * @param string $pathCommon - * @deprecated - */ - public function setTestEnvironment($pathLocal = null, $pathGlobal = null, $pathCommon = null, $allowSaving = false) - { - if (!$allowSaving) { - $this->doNotWriteConfigInTests = true; - } - - $this->reload($pathLocal, $pathGlobal, $pathCommon); - - $chain = $this->settings->getIniFileChain(); - - $databaseTestsSettings = $chain->get('database_tests'); // has to be __get otherwise when called from TestConfig, PHP will issue a NOTICE - if (!empty($databaseTestsSettings)) { - $chain->set('database', $databaseTestsSettings); - } - - // Ensure local mods do not affect tests - if (empty($pathGlobal)) { - $chain->set('Debug', $chain->getFrom($this->getGlobalPath(), 'Debug')); - $chain->set('mail', $chain->getFrom($this->getGlobalPath(), 'mail')); - $chain->set('General', $chain->getFrom($this->getGlobalPath(), 'General')); - $chain->set('Segments', $chain->getFrom($this->getGlobalPath(), 'Segments')); - $chain->set('Tracker', $chain->getFrom($this->getGlobalPath(), 'Tracker')); - $chain->set('Deletelogs', $chain->getFrom($this->getGlobalPath(), 'Deletelogs')); - $chain->set('Deletereports', $chain->getFrom($this->getGlobalPath(), 'Deletereports')); - $chain->set('Development', $chain->getFrom($this->getGlobalPath(), 'Development')); - } - - // for unit tests, we set that no plugin is installed. This will force - // the test initialization to create the plugins tables, execute ALTER queries, etc. - $chain->set('PluginsInstalled', array('PluginsInstalled' => array())); - } - - /** * Returns absolute path to the global configuration file * * @return string diff --git a/plugins/TestRunner/Commands/TestsSetupFixture.php b/plugins/TestRunner/Commands/TestsSetupFixture.php index f659eae71f..3b44a01511 100644 --- a/plugins/TestRunner/Commands/TestsSetupFixture.php +++ b/plugins/TestRunner/Commands/TestsSetupFixture.php @@ -225,12 +225,6 @@ class TestsSetupFixture extends ConsoleCommand $fixture->extraPluginsToLoad = explode(',', $extraPluginsToLoad); } - if ($fixture->createConfig) { - Config::getInstance()->setTestEnvironment($pathLocal = null, $pathGlobal = null, $pathCommon = null, $allowSave); - } - - $fixture->createConfig = false; - return $fixture; } diff --git a/tests/PHPUnit/Framework/Mock/TestConfig.php b/tests/PHPUnit/Framework/Mock/TestConfig.php index 30ba74c3a6..ef8ad61a18 100644 --- a/tests/PHPUnit/Framework/Mock/TestConfig.php +++ b/tests/PHPUnit/Framework/Mock/TestConfig.php @@ -13,7 +13,6 @@ use Piwik\Config; class TestConfig extends Config { private $allowSave = false; - private $isSettingTestEnv = false; private $doSetTestEnvironment = false; public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null, $allowSave = false, $doSetTestEnvironment = true) @@ -33,35 +32,46 @@ class TestConfig extends Config public function reload($pathLocal = null, $pathGlobal = null, $pathCommon = null) { - if ($this->isSettingTestEnv) { - parent::reload($pathGlobal, $pathLocal, $pathCommon); - } else { - $this->isSettingTestEnv = true; - $this->setTestEnvironment($pathLocal, $pathGlobal, $pathCommon, $this->allowSave); - $this->isSettingTestEnv = false; + parent::reload($pathGlobal, $pathLocal, $pathCommon); + + $this->setTestEnvironment(); + } + + public function forceSave() + { + if ($this->allowSave) { + parent::forceSave(); } } - public function setTestEnvironment($pathLocal = null, $pathGlobal = null, $pathCommon = null, $allowSaving = false) + public function setTestEnvironment() { - if ($this->doSetTestEnvironment) { - parent::setTestEnvironment($pathLocal, $pathGlobal, $pathCommon, $allowSaving); - } else { - $this->doNotWriteConfigInTests = !$allowSaving; + if (!$this->allowSave) { + $this->doNotWriteConfigInTests = true; + } - $this->pathLocal = $pathLocal ?: Config::getLocalConfigPath(); - $this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath(); - $this->pathCommon = $pathCommon ?: Config::getCommonConfigPath(); + $chain = $this->settings->getIniFileChain(); - $this->reload(); + $databaseTestsSettings = $chain->get('database_tests'); // has to be __get otherwise when called from TestConfig, PHP will issue a NOTICE + if (!empty($databaseTestsSettings)) { + $chain->set('database', $databaseTestsSettings); } - } - public function forceSave() - { - if ($this->allowSave) { - parent::forceSave(); + // Ensure local mods do not affect tests + if (empty($pathGlobal)) { + $chain->set('Debug', $chain->getFrom($this->getGlobalPath(), 'Debug')); + $chain->set('mail', $chain->getFrom($this->getGlobalPath(), 'mail')); + $chain->set('General', $chain->getFrom($this->getGlobalPath(), 'General')); + $chain->set('Segments', $chain->getFrom($this->getGlobalPath(), 'Segments')); + $chain->set('Tracker', $chain->getFrom($this->getGlobalPath(), 'Tracker')); + $chain->set('Deletelogs', $chain->getFrom($this->getGlobalPath(), 'Deletelogs')); + $chain->set('Deletereports', $chain->getFrom($this->getGlobalPath(), 'Deletereports')); + $chain->set('Development', $chain->getFrom($this->getGlobalPath(), 'Development')); } + + // for unit tests, we set that no plugin is installed. This will force + // the test initialization to create the plugins tables, execute ALTER queries, etc. + $chain->set('PluginsInstalled', array('PluginsInstalled' => array())); } private function setFromTestEnvironment(\Piwik_TestingEnvironment $testingEnvironment) |