Skip to content

Commit

Permalink
Move the Config.createConfigSingleton event handler in TestingEnviron…
Browse files Browse the repository at this point in the history
…ment.php to the TestConfig class. Since this logic is meant to be executed directly after a Config instance is created, and is only used when TestConfig is used, we can do this.
  • Loading branch information
diosmosis committed May 22, 2015
1 parent 2fd9674 commit c3c029e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
43 changes: 42 additions & 1 deletion tests/PHPUnit/Framework/Mock/TestConfig.php
Expand Up @@ -9,7 +9,6 @@
namespace Piwik\Tests\Framework\Mock;

use Piwik\Config;
use Piwik\Piwik;

class TestConfig extends Config
{
Expand All @@ -28,6 +27,9 @@ public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon =
$this->doSetTestEnvironment = $doSetTestEnvironment;

$this->reload($pathGlobal, $pathLocal, $pathCommon);

$testingEnvironment = new \Piwik_TestingEnvironment();
$this->setFromTestEnvironment($testingEnvironment);
}

public function reload($pathLocal = null, $pathGlobal = null, $pathCommon = null)
Expand Down Expand Up @@ -73,4 +75,43 @@ public function forceSave()
parent::forceSave();
}
}

private function setFromTestEnvironment(\Piwik_TestingEnvironment $testingEnvironment)
{
$pluginsToLoad = $testingEnvironment->getCoreAndSupportedPlugins();
if (!empty($testingEnvironment->pluginsToLoad)) {
$pluginsToLoad = array_unique(array_merge($pluginsToLoad, $testingEnvironment->pluginsToLoad));
}

sort($pluginsToLoad);

$chain = $this->settings->getIniFileChain();

$general =& $chain->get('General');
$plugins =& $chain->get('Plugins');
$log =& $chain->get('log');
$database =& $chain->get('database');

if ($testingEnvironment->configFileLocal) {
$general['session_save_handler'] = 'dbtable';
}

$plugins['Plugins'] = $pluginsToLoad;

$log['log_writers'] = array('file');

// TODO: replace this and below w/ configOverride use
if ($testingEnvironment->tablesPrefix) {
$database['tables_prefix'] = $testingEnvironment->tablesPrefix;
}

if ($testingEnvironment->dbName) {
$database['dbname'] = $testingEnvironment->dbName;
}

if ($testingEnvironment->configOverride) {
$cache =& $chain->getAll();
$cache = $testingEnvironment->arrayMergeRecursiveDistinct($cache, $testingEnvironment->configOverride);
}
}
}
36 changes: 0 additions & 36 deletions tests/PHPUnit/TestingEnvironment.php
Expand Up @@ -185,13 +185,6 @@ public static function addHooks($globalObservers = array())

\Piwik\Cache\Backend\File::$invalidateOpCacheBeforeRead = true;

$pluginsToLoad = $testingEnvironment->getCoreAndSupportedPlugins();
if (!empty($testingEnvironment->pluginsToLoad)) {
$pluginsToLoad = array_unique(array_merge($pluginsToLoad, $testingEnvironment->pluginsToLoad));
}

sort($pluginsToLoad);

$globalObservers[] = array('Access.createAccessSingleton', function($access) use ($testingEnvironment) {
if (!$testingEnvironment->testUseRegularAuth) {
$access = new Piwik_MockAccess($access);
Expand All @@ -200,35 +193,6 @@ public static function addHooks($globalObservers = array())
});

if (!$testingEnvironment->dontUseTestConfig) {
$globalObservers[] = array('Config.createConfigSingleton', function(IniFileChain $chain) use ($testingEnvironment, $pluginsToLoad) {
$general =& $chain->get('General');
$plugins =& $chain->get('Plugins');
$log =& $chain->get('log');
$database =& $chain->get('database');

if ($testingEnvironment->configFileLocal) {
$general['session_save_handler'] = 'dbtable';
}

$plugins['Plugins'] = $pluginsToLoad;

$log['log_writers'] = array('file');

// TODO: replace this and below w/ configOverride use
if ($testingEnvironment->tablesPrefix) {
$database['tables_prefix'] = $testingEnvironment->tablesPrefix;
}

if ($testingEnvironment->dbName) {
$database['dbname'] = $testingEnvironment->dbName;
}

if ($testingEnvironment->configOverride) {
$cache =& $chain->getAll();
$cache = $testingEnvironment->arrayMergeRecursiveDistinct($cache, $testingEnvironment->configOverride);
}
});

Config::setSingletonInstance(new TestConfig(
$testingEnvironment->configFileGlobal, $testingEnvironment->configFileLocal, $testingEnvironment->configFileCommon
));
Expand Down

0 comments on commit c3c029e

Please sign in to comment.