summaryrefslogtreecommitdiffstats
path: root/tests/mocks/database/db.php
diff options
context:
space:
mode:
authorJonatas Miguel <jonatas.df.miguel@gmail.com>2012-10-24 19:30:36 +0200
committerJonatas Miguel <jonatas.df.miguel@gmail.com>2012-10-24 19:30:36 +0200
commitb51823dde5fbae508b8ebf99258d2f514a8bece8 (patch)
tree4db09a22f85e0ddf151c940cd3e6fbaa799b8513 /tests/mocks/database/db.php
parenta53f402b78ad07fb0f6da19cff0c7bec3a09a4c0 (diff)
parenta7001e968a4791312391eb245ad84888893cda8f (diff)
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Conflicts: user_guide_src/source/changelog.rst
Diffstat (limited to 'tests/mocks/database/db.php')
-rw-r--r--tests/mocks/database/db.php45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 75658530b..7e0030e15 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -8,6 +8,16 @@ class Mock_Database_DB {
private $config = array();
/**
+ * @var string DB driver name
+ */
+ private static $dbdriver = '';
+
+ /**
+ * @var string DB sub-driver name
+ */
+ private static $subdriver = '';
+
+ /**
* Prepare database configuration skeleton
*
* @param array DB configuration to set
@@ -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,
@@ -50,7 +66,7 @@ class Mock_Database_DB {
$failover = empty($config['failover']) ? FALSE : $config['failover'];
$dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
- .'@'.$config['hostname'].'/'.$config['database'];
+ .'@'.$config['hostname'].'/'.$config['database'];
// Build the parameter
$other_params = array_slice($config, 6);
@@ -83,7 +99,32 @@ class Mock_Database_DB {
*/
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');
+ }
+
+ include_once(SYSTEM_PATH.'database/DB.php');
try
{