From 738362161b0891d7dbf5f605135d602c4e84be08 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sun, 30 May 2010 20:50:59 -0400 Subject: [PATCH] Fix specifying test configs in an environment variable --- framework/Db/test/Horde/Db/Adapter/MysqliSuite.php | 23 +++++++++++++-------- .../Db/test/Horde/Db/Adapter/Pdo/MysqlSuite.php | 24 +++++++++++++--------- .../Db/test/Horde/Db/Adapter/Pdo/PgsqlSuite.php | 23 +++++++++++++-------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/framework/Db/test/Horde/Db/Adapter/MysqliSuite.php b/framework/Db/test/Horde/Db/Adapter/MysqliSuite.php index 0f0c01619..2337f4af1 100644 --- a/framework/Db/test/Horde/Db/Adapter/MysqliSuite.php +++ b/framework/Db/test/Horde/Db/Adapter/MysqliSuite.php @@ -60,17 +60,22 @@ class Horde_Db_Adapter_MysqliSuite extends PHPUnit_Framework_TestSuite public function getConnection() { $config = getenv('DB_ADAPTER_MYSQLI_TEST_CONFIG'); - if ($config === false) { - $config = dirname(__FILE__) . '/conf.php'; - } - if (file_exists($config)) { - require $config; - } - if (!isset($conf['db']['adapter']['mysqli']['test'])) { - throw new Exception('No configuration for mysqli test.'); + if ($config && !is_file($config)) { + $config = array_merge(array('host' => 'localhost', 'username' => '', 'password' => '', 'dbname' => 'test'), json_decode($config, true)); + } else { + if (!$config) { + $config = dirname(__FILE__) . '/../conf.php'; + } + if (file_exists($config)) { + require $config; + } + if (!isset($conf['db']['adapter']['mysqli']['test'])) { + throw new Exception('No configuration for mysqli test'); + } + $config = $conf['db']['adapter']['mysqli']['test']; } - $conn = new Horde_Db_Adapter_Mysqli($conf['db']['adapter']['mysqli']['test']); + $conn = new Horde_Db_Adapter_Mysqli($config); $cache = new Horde_Cache_Mock(); $conn->setCache($cache); diff --git a/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlSuite.php b/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlSuite.php index 61da85af3..0ffda52ec 100644 --- a/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlSuite.php +++ b/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlSuite.php @@ -60,17 +60,22 @@ class Horde_Db_Adapter_Pdo_MysqlSuite extends PHPUnit_Framework_TestSuite public function getConnection() { $config = getenv('DB_ADAPTER_PDO_MYSQL_TEST_CONFIG'); - if ($config === false) { - $config = dirname(__FILE__) . '/../conf.php'; - } - if (file_exists($config)) { - require $config; - } - if (!isset($conf['db']['adapter']['pdo']['mysql']['test'])) { - throw new Exception('No configuration for pdo mysql test.'); + if ($config && !is_file($config)) { + $config = array_merge(array('host' => 'localhost', 'username' => '', 'password' => '', 'dbname' => 'test'), json_decode($config, true)); + } else { + if (!$config) { + $config = dirname(__FILE__) . '/../conf.php'; + } + if (file_exists($config)) { + require $config; + } + if (!isset($conf['db']['adapter']['pdo']['mysql']['test'])) { + throw new Exception('No configuration for pdo_mysql test'); + } + $config = $conf['db']['adapter']['pdo']['mysql']['test']; } - $conn = new Horde_Db_Adapter_Pdo_Mysql($conf['db']['adapter']['pdo']['mysql']['test']); + $conn = new Horde_Db_Adapter_Pdo_Mysql($config); $cache = new Horde_Cache_Mock(); $conn->setCache($cache); @@ -82,5 +87,4 @@ class Horde_Db_Adapter_Pdo_MysqlSuite extends PHPUnit_Framework_TestSuite { $this->sharedFixture = $this; } - } diff --git a/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlSuite.php b/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlSuite.php index 32359b683..1cc0406f9 100644 --- a/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlSuite.php +++ b/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlSuite.php @@ -63,17 +63,22 @@ class Horde_Db_Adapter_Pdo_PgsqlSuite extends PHPUnit_Framework_TestSuite if (!is_null(self::$conn)) { return self::$conn; } $config = getenv('DB_ADAPTER_PDO_PGSQL_TEST_CONFIG'); - if ($config === false) { - $config = dirname(__FILE__) . '/../conf.php'; - } - if (file_exists($config)) { - require $config; - } - if (!isset($conf['db']['adapter']['pdo']['pgsql']['test'])) { - throw new Exception('No configuration for pdo pgsql test.'); + if ($config && !is_file($config)) { + $config = array_merge(array('username' => '', 'password' => '', 'dbname' => 'test'), json_decode($config, true)); + } else { + if (!$config) { + $config = dirname(__FILE__) . '/../conf.php'; + } + if (file_exists($config)) { + require $config; + } + if (!isset($conf['db']['adapter']['pdo']['pgsql']['test'])) { + throw new Exception('No configuration for pdo_pgsql test'); + } + $config = $conf['db']['adapter']['pdo']['pgsql']['test']; } - $conn = new Horde_Db_Adapter_Pdo_Pgsql($conf['db']['adapter']['pdo']['pgsql']['test']); + $conn = new Horde_Db_Adapter_Pdo_Pgsql($config); $cache = new Horde_Cache_Mock(); $conn->setCache($cache); -- 2.11.0