Make loading, naming, and overwriting of test backend configurations consistent.
authorJan Schneider <jan@horde.org>
Wed, 5 May 2010 13:50:31 +0000 (15:50 +0200)
committerJan Schneider <jan@horde.org>
Wed, 5 May 2010 13:50:58 +0000 (15:50 +0200)
.gitignore
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
framework/Db/test/Horde/Db/Adapter/conf.php.dist [new file with mode: 0644]
framework/Db/test/Horde/Db/AllTests.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/AllTests.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/conf.php.dist [new file with mode: 0644]

index 0f76b78..bcfc0a9 100644 (file)
@@ -32,6 +32,8 @@ framework/*/test/*/*/*/*.out
 !framework/SyncML/tests/testpacket.php
 !framework/SyncML/tests/testsync.php
 !framework/XML_WBXML/tests/decode.php
+framework/Db/test/Horde/Db/Adapter/conf.php
+framework/Kolab_Storage/test/Horde/Kolab/Storage/conf.php
 
 # Dynamically generated content that may live in the repo directories
 /lib/
index 7cb4c1c..fdec080 100644 (file)
@@ -62,17 +62,19 @@ class Horde_Db_Adapter_MysqliSuite extends PHPUnit_Framework_TestSuite
         if (!class_exists('CacheMock', false)) eval('class CacheMock { function get($key) { return $this->$key; } function set($key, $val) { $this->$key = $val; } } ?>');
         $cache = new CacheMock;
 
-        $config = array(
-            'host' => 'localhost',
-            'username' => '',
-            'password' => '',
-            'dbname' => 'test',
-            'cache' => $cache,
-        );
-        if (isset($_ENV['HORDE_DB_TEST_DSN_MYSQLI']))
-            $config = array_merge($config, @json_decode($_ENV['HORDE_DB_TEST_DSN_MYSQLI'], true));
+        $config = getenv('DB_ADAPTER_MYSQLI_TEST_CONFIG');
+        if ($config === false) {
+            $config = dirname(__FILE__) . '/conf.php';
+        }
+        if (file_exists($config)) {
+            require $config;
+            $conf['db']['adapter']['mysqli']['test']['cache'] = $cache;
+        }
+        if (!isset($conf['db']['adapter']['mysqli']['test'])) {
+            throw new Exception('No configuration for mysqli test.');
+        }
 
-        $conn = new Horde_Db_Adapter_Mysqli($config);
+        $conn = new Horde_Db_Adapter_Mysqli($conf['db']['adapter']['mysqli']['test']);
         return array($conn, $cache);
     }
 
index b3fc06f..25c73fd 100644 (file)
@@ -62,17 +62,19 @@ class Horde_Db_Adapter_Pdo_MysqlSuite extends PHPUnit_Framework_TestSuite
         if (!class_exists('CacheMock', false)) eval('class CacheMock { function get($key) { return $this->$key; } function set($key, $val) { $this->$key = $val; } } ?>');
         $cache = new CacheMock;
 
-        $config = array(
-            'host' => 'localhost',
-            'username' => '',
-            'password' => '',
-            'dbname' => 'test',
-            'cache' => $cache,
-        );
-        if (isset($_ENV['HORDE_DB_TEST_DSN_PDO_MYSQL']))
-            $config = array_merge($config, @json_decode($_ENV['HORDE_DB_TEST_DSN_PDO_MYSQL'], true));
+        $config = getenv('DB_ADAPTER_PDO_MYSQL_TEST_CONFIG');
+        if ($config === false) {
+            $config = dirname(__FILE__) . '/../conf.php';
+        }
+        if (file_exists($config)) {
+            require $config;
+            $conf['db']['adapter']['pdo']['mysql']['test']['cache'] = $cache;
+        }
+        if (!isset($conf['db']['adapter']['pdo']['mysql']['test'])) {
+            throw new Exception('No configuration for pdo mysql test.');
+        }
 
-        $conn = new Horde_Db_Adapter_Pdo_Mysql($config);
+        $conn = new Horde_Db_Adapter_Pdo_Mysql($conf['db']['adapter']['pdo']['mysql']['test']);
         return array($conn, $cache);
     }
 
index f4b92e2..f6b8bff 100644 (file)
@@ -65,16 +65,19 @@ class Horde_Db_Adapter_Pdo_PgsqlSuite extends PHPUnit_Framework_TestSuite
         if (!class_exists('CacheMock', false)) eval('class CacheMock { function get($key) { return $this->$key; } function set($key, $val) { $this->$key = $val; } } ?>');
         $cache = new CacheMock;
 
-        $config = array(
-            'username' => '',
-            'password' => '',
-            'dbname' => 'test',
-            'cache' => $cache,
-        );
-        if (isset($_ENV['HORDE_DB_TEST_DSN_PDO_PGSQL']))
-            $config = array_merge($config, @json_decode($_ENV['HORDE_DB_TEST_DSN_PDO_PGSQL'], true));
+        $config = getenv('DB_ADAPTER_PDO_PGSQL_TEST_CONFIG');
+        if ($config === false) {
+            $config = dirname(__FILE__) . '/../conf.php';
+        }
+        if (file_exists($config)) {
+            require $config;
+            $conf['db']['adapter']['pdo']['pgsql']['test']['cache'] = $cache;
+        }
+        if (!isset($conf['db']['adapter']['pdo']['pgsql']['test'])) {
+            throw new Exception('No configuration for pdo pgsql test.');
+        }
 
-        $conn = new Horde_Db_Adapter_Pdo_Pgsql($config);
+        $conn = new Horde_Db_Adapter_Pdo_Pgsql($conf['db']['adapter']['pdo']['pgsql']['test']);
         return array($conn, $cache);
     }
 
diff --git a/framework/Db/test/Horde/Db/Adapter/conf.php.dist b/framework/Db/test/Horde/Db/Adapter/conf.php.dist
new file mode 100644 (file)
index 0000000..37daf95
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+$conf['db']['adapter']['mysqli']['test']['host'] = 'localhost';
+$conf['db']['adapter']['mysqli']['test']['username'] = '';
+$conf['db']['adapter']['mysqli']['test']['password'] = '';
+$conf['db']['adapter']['mysqli']['test']['dbname'] = 'test';
+$conf['db']['adapter']['pdo']['mysql']['test']['host'] = 'localhost';
+$conf['db']['adapter']['pdo']['mysql']['test']['username'] = '';
+$conf['db']['adapter']['pdo']['mysql']['test']['password'] = '';
+$conf['db']['adapter']['pdo']['mysql']['test']['dbname'] = 'test';
+$conf['db']['adapter']['pdo']['pgsql']['test']['username'] = '';
+$conf['db']['adapter']['pdo']['pgsql']['test']['password'] = '';
+$conf['db']['adapter']['pdo']['pgsql']['test']['dbname'] = 'test';
index 7759557..c929c61 100644 (file)
@@ -34,6 +34,14 @@ date_default_timezone_set('America/New_York');
  */
 class Horde_Db_AllTests extends Horde_Test_AllTests
 {
+    /**
+     * Main entry point for running the suite.
+     */
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+
     public static function suite()
     {
         // Catch strict standards
index 9e378a2..66b842c 100644 (file)
@@ -42,7 +42,7 @@ class Horde_Kolab_Storage_AllTests extends Horde_Test_AllTests
             self::$_file = $file;
         }
 
-        PHPUnit_TextUI_TestRunner::run(self::detectTestFixture(self::suite()));
+        PHPUnit_TextUI_TestRunner::run(self::suite());
     }
 
     /**
@@ -63,9 +63,9 @@ class Horde_Kolab_Storage_AllTests extends Horde_Test_AllTests
      */
     public static function detectTestFixture(PHPUnit_Framework_TestSuite $suite)
     {
-        $config = getenv('KOLAB_TEST_CONFIG');
+        $config = getenv('KOLAB_STORAGE_TEST_CONFIG');
         if ($config === false) {
-            $config = '/kolab/etc/kolab/php_unit_server_testing.php';
+            $config = dirname(__FILE__) . '/conf.php';
         }
         if (file_exists($config)) {
             require $config;
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/conf.php.dist b/framework/Kolab_Storage/test/Horde/Kolab/Storage/conf.php.dist
new file mode 100644 (file)
index 0000000..9cef874
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+$conf['kolab']['storage']['test']['host'] = 'localhost';
+$conf['kolab']['storage']['test']['user'] = '';
+$conf['kolab']['storage']['test']['pass'] = '';
+$conf['kolab']['storage']['test']['debug'] = '';