Browse files

Adapted DB for VFS changes and fixed Common case in Bootstrap.php

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
1 parent 93ec20b commit e9435dc7e5a4a9779eb83d8adf172fabf47ab5a6 @dchill42 committed Oct 14, 2012
Showing with 61 additions and 4 deletions.
  1. +1 −1 tests/Bootstrap.php
  2. +7 −1 tests/mocks/autoloader.php
  3. +10 −0 tests/mocks/ci_testcase.php
  4. +43 −2 tests/mocks/database/db.php
View
2 tests/Bootstrap.php
@@ -38,7 +38,7 @@ class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
// Prep our test environment
include_once $dir.'/mocks/core/common.php';
-include_once SYSTEM_PATH.'core/common.php';
+include_once SYSTEM_PATH.'core/Common.php';
include_once $dir.'/mocks/autoloader.php';
spl_autoload_register('autoload');
View
8 tests/mocks/autoloader.php
@@ -65,6 +65,12 @@ function autoload($class)
$dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
$class = $subclass;
}
+ elseif (preg_match('/^CI_DB_(.+)_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 4)
+ {
+ $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR.'subdrivers'.DIRECTORY_SEPARATOR;
+ $file = $dir.$m[1].'_'.$m[2].'_'.$m[3].'.php';
+ }
elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3)
{
$driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
@@ -104,4 +110,4 @@ function autoload($class)
}
include_once($file);
-}
+}
View
10 tests/mocks/ci_testcase.php
@@ -275,6 +275,16 @@ public function ci_vfs_create($file, $content = '', $root = NULL, $path = NULL)
*/
public function ci_vfs_clone($path)
{
+ // Check for array
+ if (is_array($path))
+ {
+ foreach ($path as $file)
+ {
+ $this->ci_vfs_clone($file);
+ }
+ return;
+ }
+
// Get real file contents
$content = file_get_contents(PROJECT_BASE.$path);
if ($content === FALSE)
View
45 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 @@ public function set_dsn($group = 'default')
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 @@ public function set_dsn($group = 'default')
$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 @@ public static function config($driver)
*/
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
{

0 comments on commit e9435dc

Please sign in to comment.