summaryrefslogtreecommitdiffstats
path: root/tests/mocks/database/db.php
diff options
context:
space:
mode:
authorEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
committerEric Roberts <eric@cryode.com>2012-12-12 14:02:11 +0100
commitb9e35f21e1c70b6aa67c47e9244ed83195abc00a (patch)
tree64f82db362deeac48cc20d1d1afd80651f36f5a5 /tests/mocks/database/db.php
parent0b05705c52c3bca7f9b3aee657c888e8ad1ff422 (diff)
parent545a7c86701875e1412bcde316e9bcc76d9a23a0 (diff)
Merge branch 'refs/heads/develop' into feature/form_error_msgs
Conflicts: system/language/english/form_validation_lang.php user_guide_src/source/libraries/form_validation.rst Signed-off-by: Eric Roberts <eric@cryode.com>
Diffstat (limited to 'tests/mocks/database/db.php')
-rw-r--r--tests/mocks/database/db.php80
1 files changed, 60 insertions, 20 deletions
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 43a0d391f..7e0030e15 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -6,7 +6,17 @@ class Mock_Database_DB {
* @var array DB configuration
*/
private $config = array();
-
+
+ /**
+ * @var string DB driver name
+ */
+ private static $dbdriver = '';
+
+ /**
+ * @var string DB sub-driver name
+ */
+ private static $subdriver = '';
+
/**
* Prepare database configuration skeleton
*
@@ -21,7 +31,7 @@ class Mock_Database_DB {
/**
* Build DSN connection string for DB driver instantiate process
*
- * @param string Group name
+ * @param string Group name
* @return string DSN Connection string
*/
public function set_dsn($group = 'default')
@@ -31,6 +41,12 @@ class Mock_Database_DB {
throw new InvalidArgumentException('Group '.$group.' not exists');
}
+ self::$dbdriver = $this->config[$group]['dbdriver'];
+ if (isset($this->config[$group]['subdriver']))
+ {
+ self::$subdriver = $this->config[$group]['subdriver'];
+ }
+
$params = array(
'dbprefix' => '',
'pconnect' => FALSE,
@@ -45,19 +61,18 @@ class Mock_Database_DB {
);
$config = array_merge($this->config[$group], $params);
+ $dsnstring = empty($config['dsn']) ? FALSE : $config['dsn'];
+ $subdriver = empty($config['subdriver']) ? FALSE: $config['subdriver'];
+ $failover = empty($config['failover']) ? FALSE : $config['failover'];
- if ( ! empty($config['dsn']))
- {
- $dsn = $config['dsn'];
- }
- else
- {
- $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
- .'@'.$config['hostname'].'/'.$config['database'];
-
- }
+ $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
+ .'@'.$config['hostname'].'/'.$config['database'];
+ // Build the parameter
$other_params = array_slice($config, 6);
+ if ($dsnstring) $other_params['dsn'] = $dsnstring;
+ if ($subdriver) $other_params['subdriver'] = $subdriver;
+ if ($failover) $other_params['failover'] = $failover;
return $dsn.'?'.http_build_query($other_params);
}
@@ -66,28 +81,52 @@ class Mock_Database_DB {
* Return a database config array
*
* @see ./config
- * @param string Driver based configuration
- * @return array
+ * @param string Driver based configuration
+ * @return array
*/
public static function config($driver)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
-
return include($dir.'config'.DIRECTORY_SEPARATOR.$driver.'.php');
}
/**
* Main DB method wrapper
*
- * @param string Group or DSN string
- * @param bool
- * @return object
+ * @param string Group or DSN string
+ * @param bool
+ * @return object
*/
public static function DB($group, $query_builder = FALSE)
{
- include_once(BASEPATH.'database/DB.php');
+ // Create dummy driver and builder files to "load" - the mocks have
+ // already triggered autoloading of the real files
+ $case = CI_TestCase::instance();
+ $driver = self::$dbdriver;
+ $subdriver = self::$subdriver;
+ $case->ci_vfs_create(array(
+ 'DB_driver.php' => '',
+ 'DB_forge.php' => '',
+ 'DB_query_builder.php' => ''
+ ), '', $case->ci_base_root, 'database');
+ if (file_exists(SYSTEM_PATH.'database/drivers/'.$driver.'/'.$driver.'_driver.php'))
+ {
+ $case->ci_vfs_create(array(
+ $driver.'_driver.php' => '',
+ $driver.'_forge.php' => ''
+ ), '', $case->ci_base_root, 'database/drivers/'.$driver);
+ }
+ if ($subdriver)
+ {
+ $case->ci_vfs_create(array(
+ $driver.'_'.$subdriver.'_driver.php' => '',
+ $driver.'_'.$subdriver.'_forge.php' => ''
+ ), '', $case->ci_base_root, 'database/drivers/'.$driver.'/subdrivers');
+ }
- try
+ include_once(SYSTEM_PATH.'database/DB.php');
+
+ try
{
$db = DB($group, $query_builder);
}
@@ -98,4 +137,5 @@ class Mock_Database_DB {
return $db;
}
+
} \ No newline at end of file