!framework/XML_WBXML/tests/decode.php
framework/Alarm/test/Horde/Alarm/conf.php
framework/Db/test/Horde/Db/Adapter/conf.php
+framework/Db/test/Horde/Db/Adapter/Pdo/conf.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/conf.php
framework/Ldap/test/Horde/Ldap/conf.php
* @subpackage UnitTests
*/
-class Horde_Alarm_SqlTest extends PHPUnit_Framework_TestCase
+class Horde_Alarm_SqlTest extends Horde_Test_Case
{
protected static $skip = false;
protected static $db;
// @fixme
$GLOBALS['language'] = 'en_US';
- $config = getenv('ALARM_TEST_CONFIG');
- if ($config === false) {
- $config = dirname(__FILE__) . '/conf.php';
- }
- if (file_exists($config)) {
- require $config;
- }
+ $conf = self::getConfig('ALARM_TEST_CONFIG');
if (!isset($conf['alarm']['test'])) {
self::$skip = true;
return;
public function getConnection()
{
- $config = getenv('DB_ADAPTER_MYSQL_TEST_CONFIG');
- if ($config && !is_dir(dirname($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']['mysql']['test'])) {
- throw new Exception('No configuration for mysql test');
- }
- $config = $conf['db']['adapter']['mysql']['test'];
+ $config = Horde_Test_Case::getConfig('DB_ADAPTER_MYSQL_TEST_CONFIG',
+ array('host' => 'localhost',
+ 'username' => '',
+ 'password' => '',
+ 'dbname' => 'test'));
+ if (isset($config['db']['adapter']['mysql']['test'])) {
+ $config = $config['db']['adapter']['mysql']['test'];
+ }
+ if (!is_array($config)) {
+ throw new Exception('No configuration for mysql test');
}
$conn = new Horde_Db_Adapter_Mysql($config);
public function getConnection()
{
- $config = getenv('DB_ADAPTER_MYSQLI_TEST_CONFIG');
- if ($config && !is_dir(dirname($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'];
+ $config = Horde_Test_Case::getConfig('DB_ADAPTER_MYSQLI_TEST_CONFIG',
+ array('host' => 'localhost',
+ 'username' => '',
+ 'password' => '',
+ 'dbname' => 'test'));
+ if (isset($config['db']['adapter']['mysqli']['test'])) {
+ $config = $config['db']['adapter']['mysqli']['test'];
+ }
+ if (!is_array($config)) {
+ throw new Exception('No configuration for mysql test');
}
$conn = new Horde_Db_Adapter_Mysqli($config);
public function getConnection()
{
- $config = getenv('DB_ADAPTER_PDO_MYSQL_TEST_CONFIG');
- if ($config && !is_dir(dirname($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'];
+ $config = Horde_Test_Case::getConfig('DB_ADAPTER_PDO_MYSQL_TEST_CONFIG',
+ array('host' => 'localhost',
+ 'username' => '',
+ 'password' => '',
+ 'dbname' => 'test'));
+ if (isset($config['db']['adapter']['pdo']['mysql']['test'])) {
+ $config = $config['db']['adapter']['pdo']['mysql']['test'];
+ }
+ if (!is_array($config)) {
+ throw new Exception('No configuration for pdo_mysql test');
}
$conn = new Horde_Db_Adapter_Pdo_Mysql($config);
return self::$conn;
}
- $config = getenv('DB_ADAPTER_PDO_PGSQL_TEST_CONFIG');
- if ($config && !is_dir(dirname($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'];
+ $config = Horde_Test_Case::getConfig('DB_ADAPTER_PDO_PGSQL_TEST_CONFIG',
+ array('username' => '',
+ 'password' => '',
+ 'dbname' => 'test'));
+ if (isset($config['db']['adapter']['pdo']['pgsql']['test'])) {
+ $config = $config['db']['adapter']['pdo']['pgsql']['test'];
+ }
+ if (!is_array($config)) {
+ throw new Exception('No configuration for pdo_pgsql test');
}
$conn = new Horde_Db_Adapter_Pdo_Pgsql($config);
<?php
+// IMPORTANT: the conf.php version of this file must be both in this directory
+// and in the the Pdo/ subdirectory. A symlink is fine too.
$conf['db']['adapter']['mysql']['test']['host'] = 'localhost';
$conf['db']['adapter']['mysql']['test']['username'] = '';
$conf['db']['adapter']['mysql']['test']['password'] = '';
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*/
-class Horde_Ldap_TestBase extends PHPUnit_Framework_TestCase
+class Horde_Ldap_TestBase extends Horde_Test_Case
{
protected static $ldapcfg;
$this->markTestSkipped($e->getMessage());
}
- $file = dirname(__FILE__) . '/conf.php';
- if (!file_exists($file) || !is_readable($file)) {
- $this->markTestSkipped('conf.php cannot be opened.');
+ $config = $this->getConfig('LDAP_TEST_CONFIG');
+ if (!$config) {
+ $this->markTestSkipped('No configuration for LDAP tests.');
}
- include $file;
- self::$ldapcfg = $conf;
+ self::$ldapcfg = $config;
}
}
{
return $this->getMock($className, $methods, $arguments, $mockClassName, /* $callOriginalConstructor */ false);
}
+
+ /**
+ * Helper method for loading test configuration from a file.
+ *
+ * The configuration can be specified by an environment variable. If the
+ * variable content is a file name, the configuration is loaded from the
+ * file. Otherwise it's assumed to be a json encoded configuration hash. If
+ * the environment variable is not set, the method tries to load a conf.php
+ * file from the same directory as the test case.
+ *
+ * @param string $env An environment variable name.
+ * @param array $default Some default values that are merged into the
+ * configuration if specified as a json hash.
+ *
+ * @return mixed The value of the configuration file's $conf variable, or
+ * null.
+ */
+ static public function getConfig($env, $default = array())
+ {
+ $conf = null;
+ $config = getenv($env);
+ if ($config && !is_dir(dirname($config))) {
+ $conf = Horde_Array::replaceRecursive($default,
+ json_decode($config, true));
+ } elseif ($config === false) {
+ $backtrace = new Horde_Support_Backtrace();
+ $caller = $backtrace->getCurrentContext();
+ $config = dirname($caller['file']) . '/conf.php';
+ }
+ if (file_exists($config)) {
+ require $config;
+ }
+ return $conf;
+ }
}