From 132e9ce3c02bdb33bf2294dde6a45a65f2f23c3f Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 1 Jun 2014 13:43:35 +0200 Subject: [PATCH] Simplified test config management --- src/core.php | 23 +++++++++++------------ tests/SzurubooruTestRunner.php | 18 +++++++++++------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/core.php b/src/core.php index dac77d99..9812a698 100644 --- a/src/core.php +++ b/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'; - } + $configPaths []= self::$rootDir . DS . 'data' . DS . 'config.ini'; + $configPaths []= self::$rootDir . DS . 'data' . DS . 'local.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(); diff --git a/tests/SzurubooruTestRunner.php b/tests/SzurubooruTestRunner.php index 4b26ee53..38ce0843 100644 --- a/tests/SzurubooruTestRunner.php +++ b/tests/SzurubooruTestRunner.php @@ -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)