Skip to content
Extraits de code Groupes Projets
Valider 4a4f512f rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Add config_override testing environment parameter that overrides INI config...

Add config_override testing environment parameter that overrides INI config values, and make sure fixtures post testingenvironment hook so plugin test environment is enabled for fixtures.
parent 605596a6
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -69,6 +69,11 @@ class Fixture extends PHPUnit_Framework_Assert
public $testEnvironment = null;
public function __construct()
{
$this->testEnvironment = new Piwik_TestingEnvironment();
}
/** Adds data to Piwik. Creates sites, tracks visits, imports log files, etc. */
public function setUp()
{
......@@ -83,7 +88,6 @@ class Fixture extends PHPUnit_Framework_Assert
public function performSetUp($testCase, $setupEnvironmentOnly = false)
{
$this->testEnvironment = new Piwik_TestingEnvironment();
$this->testEnvironment->delete();
try {
......@@ -182,6 +186,7 @@ class Fixture extends PHPUnit_Framework_Assert
}
$this->testEnvironment->save();
$this->testEnvironment->executeSetupTestEnvHook();
if ($this->overwriteExisting
|| !$this->isFixtureSetUp()
......@@ -682,17 +687,19 @@ class Fixture extends PHPUnit_Framework_Assert
Piwik::postEvent('Request.initAuthenticationObject');
}
private function dropDatabase()
public function dropDatabase($dbName = null)
{
$dbName = $dbName ?: $this->dbName;
$config = _parse_ini_file(PIWIK_INCLUDE_PATH . '/config/config.ini.php', true);
$originalDbName = $config['database']['dbname'];
if ($this->dbName == $originalDbName
&& $this->dbName != 'piwik_tests'
if ($dbName == $originalDbName
&& $dbName != 'piwik_tests'
) { // santity check
throw new \Exception("Trying to drop original database '$originalDbName'. Something's wrong w/ the tests.");
}
DbHelper::dropDatabase();
DbHelper::dropDatabase($dbName);
}
public function log($message)
......
......@@ -122,6 +122,7 @@ class Piwik_TestingEnvironment
$manager->unloadPlugins();
// TODO: replace this and below w/ configOverride use
if ($testingEnvironment->tablesPrefix) {
$cache['database']['tables_prefix'] = $testingEnvironment->tablesPrefix;
}
......@@ -130,6 +131,10 @@ class Piwik_TestingEnvironment
$cache['database']['dbname'] = $testingEnvironment->dbName;
}
if ($testingEnvironment->configOverride) {
$cache = array_merge_recursive($cache, $testingEnvironment->configOverride);
}
$testingEnvironment->logVariables();
});
}
......@@ -168,6 +173,14 @@ class Piwik_TestingEnvironment
}
});
Piwik::postEvent("TestingEnvironment.addHooks", array($testingEnvironment), $pending = true); // for plugins that need to inject special testing logic
$testingEnvironment->executeSetupTestEnvHook();
}
/**
* for plugins that need to inject special testing logic
*/
public function executeSetupTestEnvHook()
{
Piwik::postEvent("TestingEnvironment.addHooks", array($this), $pending = true);
}
}
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter