Fix specifying test configs in an environment variable
authorChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 00:50:59 +0000 (20:50 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 01:30:32 +0000 (21:30 -0400)
framework/Db/test/Horde/Db/Adapter/MysqliSuite.php
framework/Db/test/Horde/Db/Adapter/Pdo/MysqlSuite.php
framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlSuite.php

index 0f0c016..2337f4a 100644 (file)
@@ -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);
index 61da85a..0ffda52 100644 (file)
@@ -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;
     }
-
 }
index 32359b6..1cc0406 100644 (file)
@@ -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);