Simplified test config management

This commit is contained in:
Marcin Kurczewski 2014-06-01 13:43:35 +02:00
parent 4ec0df17d6
commit 132e9ce3c0
2 changed files with 22 additions and 19 deletions

View file

@ -48,18 +48,17 @@ final class Core
return self::$database; return self::$database;
} }
static function prepareConfig($testEnvironment) static function setConfig(\Chibi\Config $config)
{
self::$config = $config;
self::$config->rootDir = self::$rootDir;
}
static function prepareConfig()
{ {
$configPaths = []; $configPaths = [];
if (!$testEnvironment) $configPaths []= self::$rootDir . DS . 'data' . DS . 'config.ini';
{ $configPaths []= self::$rootDir . DS . 'data' . DS . 'local.ini';
$configPaths []= self::$rootDir . DS . 'data' . DS . 'config.ini';
$configPaths []= self::$rootDir . DS . 'data' . DS . 'local.ini';
}
else
{
$configPaths []= self::$rootDir . DS . 'tests' . DS . 'config.ini';
}
self::$config = new \Chibi\Config(); self::$config = new \Chibi\Config();
foreach ($configPaths as $path) foreach ($configPaths as $path)
@ -194,6 +193,6 @@ final class Core
} }
Core::init(); Core::init();
Core::prepareConfig(false); Core::prepareConfig();
Core::prepareDatabase(); Core::prepareDatabase();
Core::prepareEnvironment(false); Core::prepareEnvironment();

View file

@ -11,6 +11,7 @@ class SzurubooruTestRunner implements ITestRunner
exit(0); exit(0);
} }
$this->prepareTestConfig($options);
$this->connectToDatabase($options); $this->connectToDatabase($options);
if ($options->cleanDatabase) if ($options->cleanDatabase)
$this->cleanDatabase(); $this->cleanDatabase();
@ -144,7 +145,6 @@ class SzurubooruTestRunner implements ITestRunner
private function connectToDatabase($options) private function connectToDatabase($options)
{ {
$this->prepareTestConfig($options);
Core::prepareDatabase(); Core::prepareDatabase();
if ($options->dbDriver == 'mysql') if ($options->dbDriver == 'mysql')
@ -156,19 +156,23 @@ class SzurubooruTestRunner implements ITestRunner
private function prepareTestConfig($options) private function prepareTestConfig($options)
{ {
Core::prepareConfig(true); $config = new \Chibi\Config();
$config->loadIni(Core::getConfig()->rootDir . DS . 'tests' . DS . 'config.ini');
$config->isForTests = true;
Core::getConfig()->main->dbDriver = $options->dbDriver; $config->main->dbDriver = $options->dbDriver;
if ($options->dbDriver == 'sqlite') if ($options->dbDriver == 'sqlite')
{ {
Core::getConfig()->main->dbLocation = $this->getSqliteDatabasePath(); $config->main->dbLocation = $this->getSqliteDatabasePath();
} }
elseif ($options->dbDriver == 'mysql') elseif ($options->dbDriver == 'mysql')
{ {
Core::getConfig()->main->dbLocation = $this->getMysqlDatabaseName(); $config->main->dbLocation = $this->getMysqlDatabaseName();
Core::getConfig()->main->dbUser = 'test'; $config->main->dbUser = 'test';
Core::getConfig()->main->dbPass = 'test'; $config->main->dbPass = 'test';
} }
Core::setConfig($config);
} }
private function resetEnvironment($options) private function resetEnvironment($options)