Simplified test config management
This commit is contained in:
parent
4ec0df17d6
commit
132e9ce3c0
2 changed files with 22 additions and 19 deletions
19
src/core.php
19
src/core.php
|
@ -48,18 +48,17 @@ final class Core
|
|||
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 = [];
|
||||
if (!$testEnvironment)
|
||||
{
|
||||
$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();
|
||||
foreach ($configPaths as $path)
|
||||
|
@ -194,6 +193,6 @@ final class Core
|
|||
}
|
||||
|
||||
Core::init();
|
||||
Core::prepareConfig(false);
|
||||
Core::prepareConfig();
|
||||
Core::prepareDatabase();
|
||||
Core::prepareEnvironment(false);
|
||||
Core::prepareEnvironment();
|
||||
|
|
|
@ -11,6 +11,7 @@ class SzurubooruTestRunner implements ITestRunner
|
|||
exit(0);
|
||||
}
|
||||
|
||||
$this->prepareTestConfig($options);
|
||||
$this->connectToDatabase($options);
|
||||
if ($options->cleanDatabase)
|
||||
$this->cleanDatabase();
|
||||
|
@ -144,7 +145,6 @@ class SzurubooruTestRunner implements ITestRunner
|
|||
|
||||
private function connectToDatabase($options)
|
||||
{
|
||||
$this->prepareTestConfig($options);
|
||||
Core::prepareDatabase();
|
||||
|
||||
if ($options->dbDriver == 'mysql')
|
||||
|
@ -156,19 +156,23 @@ class SzurubooruTestRunner implements ITestRunner
|
|||
|
||||
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')
|
||||
{
|
||||
Core::getConfig()->main->dbLocation = $this->getSqliteDatabasePath();
|
||||
$config->main->dbLocation = $this->getSqliteDatabasePath();
|
||||
}
|
||||
elseif ($options->dbDriver == 'mysql')
|
||||
{
|
||||
Core::getConfig()->main->dbLocation = $this->getMysqlDatabaseName();
|
||||
Core::getConfig()->main->dbUser = 'test';
|
||||
Core::getConfig()->main->dbPass = 'test';
|
||||
$config->main->dbLocation = $this->getMysqlDatabaseName();
|
||||
$config->main->dbUser = 'test';
|
||||
$config->main->dbPass = 'test';
|
||||
}
|
||||
|
||||
Core::setConfig($config);
|
||||
}
|
||||
|
||||
private function resetEnvironment($options)
|
||||
|
|
Loading…
Reference in a new issue