From ff310f56c57527f99f9fec04dd4818c967cc7ca1 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 30 Aug 2014 18:11:04 +0200 Subject: [PATCH] Changed config.ini hierarchy --- config.ini | 10 +++++++--- src/DatabaseConnection.php | 8 ++++---- tests/AbstractDatabaseTest.php | 7 ++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config.ini b/config.ini index 4a07f1b8..c92233e8 100644 --- a/config.ini +++ b/config.ini @@ -1,3 +1,7 @@ -databaseHost = localhost -databasePort = 27017; -databaseName = booru-dev +[database] +host = localhost +port = 27017; +name = booru-dev + +[security] +secret = change diff --git a/src/DatabaseConnection.php b/src/DatabaseConnection.php index e5e8e2a8..7c5840c9 100644 --- a/src/DatabaseConnection.php +++ b/src/DatabaseConnection.php @@ -10,7 +10,7 @@ final class DatabaseConnection { $connectionString = $this->getConnectionString($config); $this->connection = new \MongoClient($connectionString); - $this->database = $this->connection->selectDb($config->databaseName); + $this->database = $this->connection->selectDb($config->database->name); } public function getConnection() @@ -27,8 +27,8 @@ final class DatabaseConnection { return sprintf( 'mongodb://%s:%d/%s', - $config->databaseHost, - $config->databasePort, - $config->databaseName); + $config->database->host, + $config->database->port, + $config->database->name); } } diff --git a/tests/AbstractDatabaseTest.php b/tests/AbstractDatabaseTest.php index df36f1d9..12dfcb2d 100644 --- a/tests/AbstractDatabaseTest.php +++ b/tests/AbstractDatabaseTest.php @@ -12,9 +12,10 @@ abstract class AbstractDatabaseTest extends \PHPUnit_Framework_TestCase $port = 27017; $database = 'test'; $config = new \Szurubooru\Config(); - $config->databaseHost = 'localhost'; - $config->databasePort = 27017; - $config->databaseName = 'test'; + $config->database = new \StdClass; + $config->database->host = 'localhost'; + $config->database->port = 27017; + $config->database->name = 'test'; $this->databaseConnection = new \Szurubooru\DatabaseConnection($config); $this->upgradeService = new \Szurubooru\UpgradeService($this->databaseConnection); $this->upgradeService->prepareForUsage();