Merge pull request #1246 from toopay/db-tests

Improved test coverage for Database.
diff --git a/.travis.yml b/.travis.yml
index 84029b9..97ea042 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,14 +8,17 @@
   - DB=mysql
   - DB=pgsql
   - DB=sqlite
+  - DB=pdo/mysql
+  - DB=pdo/pgsql
+  - DB=pdo/sqlite
 
 before_script:
   - pyrus channel-discover pear.php-tools.net
   - pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz
   - phpenv rehash
-  - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
-  - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
-  - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
+  - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi"
+  - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi"
+  - sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi"
 
 script: phpunit --configuration tests/travis/$DB.phpunit.xml
 
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
new file mode 100644
index 0000000..fb40f06
--- /dev/null
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -0,0 +1,36 @@
+<?php
+
+class DB_driver_test extends CI_TestCase {
+
+	// ------------------------------------------------------------------------
+
+	public function test_initialize()
+	{
+		$config = Mock_Database_DB::config(DB_DRIVER);
+		$driver_name = current(explode('/', DB_DRIVER));
+		$driver = $this->$driver_name($config[DB_DRIVER]);
+
+		$this->assertTrue($driver->initialize());
+	}
+
+	protected function pdo($config)
+	{
+		return new Mock_Database_Drivers_PDO($config);
+	}
+
+	protected function mysql($config)
+	{
+		return new Mock_Database_Drivers_Mysql($config);
+	}
+
+	protected function sqlite($config)
+	{
+		return new Mock_Database_Drivers_Sqlite($config);
+	}
+
+	protected function pgsql($config)
+	{
+		return new Mock_Database_Drivers_Postgre($config);
+	}
+	
+}
\ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep
deleted file mode 100644
index e69de29..0000000
--- a/tests/codeigniter/database/query_builder/.gitkeep
+++ /dev/null
diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php
new file mode 100644
index 0000000..0751c93
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/get_test.php
@@ -0,0 +1,53 @@
+<?php
+
+class Get_test extends CI_TestCase {
+
+	/**
+	 * @var object Database/Query Builder holder
+	 */
+	protected $db;
+
+	public function set_up()
+	{
+		$this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+		Mock_Database_Schema_Skeleton::create_tables();
+		Mock_Database_Schema_Skeleton::create_data();
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_get_simple()
+	{
+		$jobs = $this->db->get('job')->result_array();
+		
+		// Dummy jobs contain 4 rows
+		$this->assertCount(4, $jobs);
+
+		// Check rows item
+		$this->assertEquals('Developer', $jobs[0]['name']);
+		$this->assertEquals('Politician', $jobs[1]['name']);
+		$this->assertEquals('Accountant', $jobs[2]['name']);
+		$this->assertEquals('Musician', $jobs[3]['name']);
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_get_where()
+	{
+		$job1 = $this->db->get('job', array('id' => 1))->result_array();
+		
+		// Dummy jobs contain 1 rows
+		$this->assertCount(1, $job1);
+
+		// Check rows item
+		$this->assertEquals('Developer', $job1[0]['name']);
+	}
+	
+}
\ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php
new file mode 100644
index 0000000..53ce23c
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/insert_test.php
@@ -0,0 +1,67 @@
+<?php
+
+class Insert_test extends CI_TestCase {
+
+	/**
+	 * @var object Database/Query Builder holder
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	protected $db;
+
+	public function set_up()
+	{
+		$this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+		Mock_Database_Schema_Skeleton::create_tables();
+
+		// Truncate the current datas
+		$this->db->truncate('job');
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_insert()
+	{
+		$job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!');
+		
+		// Do normal insert
+		$this->assertTrue($this->db->insert('job', $job_data));
+
+		$jobs = $this->db->get('job')->result_array();
+		$job1 = $jobs[0];
+
+		// Check the result
+		$this->assertEquals('Grocery Sales', $job1['name']);
+
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_insert_batch()
+	{
+		$job_datas = array(
+			array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), 
+			array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'),
+		);
+		
+		// Do insert batch except for sqlite driver
+		if (strpos(DB_DRIVER, 'sqlite') === FALSE)
+		{
+			$this->assertTrue($this->db->insert_batch('job', $job_datas));
+
+			$job_2 = $this->db->where('id', 2)->get('job')->row();
+			$job_3 = $this->db->where('id', 3)->get('job')->row();
+
+			// Check the result
+			$this->assertEquals('Commedian', $job_2->name);
+			$this->assertEquals('Cab Driver', $job_3->name);
+		}
+	}
+	
+}
\ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php
new file mode 100644
index 0000000..dbf432a
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/select_test.php
@@ -0,0 +1,95 @@
+<?php
+
+class Select_test extends CI_TestCase {
+
+	/**
+	 * @var object Database/Query Builder holder
+	 */
+	protected $db;
+
+	public function set_up()
+	{
+		$this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+		Mock_Database_Schema_Skeleton::create_tables();
+		Mock_Database_Schema_Skeleton::create_data();
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_select_only_one_collumn()
+	{
+		$jobs_name = $this->db->select('name')
+		                      ->get('job')
+		                      ->result_array();
+		
+		// Check rows item
+		$this->assertArrayHasKey('name',$jobs_name[0]);
+		$this->assertFalse(array_key_exists('id', $jobs_name[0]));
+		$this->assertFalse(array_key_exists('description', $jobs_name[0]));
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_select_min()
+	{
+		$job_min = $this->db->select_min('id')
+		                    ->get('job')
+		                    ->result_array();
+		
+		// Minimum id was 1
+		$this->assertEquals('1', $job_min[0]['id']);
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_select_max()
+	{
+		$job_max = $this->db->select_max('id')
+		                    ->get('job')
+		                    ->result_array();
+		
+		// Maximum id was 4
+		$this->assertEquals('4', $job_max[0]['id']);
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_select_avg()
+	{
+		$job_avg = $this->db->select_avg('id')
+		                    ->get('job')
+		                    ->result_array();
+		
+		// Average should be 2.5
+		$this->assertEquals('2.5', $job_avg[0]['id']);
+	}
+
+	// ------------------------------------------------------------------------
+
+	/**
+	 * @see ./mocks/schema/skeleton.php
+	 */
+	public function test_select_sum()
+	{
+		$job_sum = $this->db->select_sum('id')
+		                    ->get('job')
+		                    ->result_array();
+		
+		// Sum of ids should be 10
+		$this->assertEquals('10', $job_sum[0]['id']);
+	}
+	
+}
\ No newline at end of file
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index dd59292..f1bdb5d 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -53,13 +53,24 @@
 			$dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
 			$class = $subclass;
 		}
+		elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) == 3)
+		{
+			$driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+			$dir = $driver_path.$m[1].DIRECTORY_SEPARATOR;
+			$file = $dir.$m[1].'_'.$m[2].'.php';
+		}
+		elseif (strpos($class, 'CI_DB') === 0)
+		{
+			$dir = BASEPATH.'database'.DIRECTORY_SEPARATOR;
+			$file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php';
+		}
 		else
 		{
 			$class = strtolower($class);
 		}
 	}
 
-	$file = $dir.$class.'.php';
+	$file = (isset($file)) ? $file : $dir.$class.'.php';
 
 	if ( ! file_exists($file))
 	{
@@ -71,7 +82,7 @@
 		{
 			return FALSE;
 		}
-
+		
 	    throw new InvalidArgumentException("Unable to load $class.");
 	}
 
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 37ce4f8..86d868a 100755
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php
new file mode 100644
index 0000000..cefb6b0
--- /dev/null
+++ b/tests/mocks/database/config/pdo/mysql.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+	
+	// Typical Database configuration
+	'pdo/mysql' => array(
+		'dsn' => '',
+		'hostname' => 'localhost',
+		'username' => 'travis',
+		'password' => '',
+		'database' => 'ci_test',
+		'dbdriver' => 'pdo',
+		'pdodriver' => 'mysql',
+	),
+
+	// Database configuration with failover
+	'pdo/mysql_failover' => array(
+		'dsn' => '',
+		'hostname' => 'localhost',
+		'username' => 'not_travis',
+		'password' => 'wrong password',
+		'database' => 'not_ci_test',
+		'dbdriver' => 'pdo',
+		'pdodriver' => 'mysql',
+		'failover' => array(
+			array(
+				'dsn' => '',
+				'hostname' => 'localhost',
+				'username' => 'travis',
+				'password' => '',
+				'database' => 'ci_test',
+				'dbdriver' => 'pdo',
+				'pdodriver' => 'mysql',
+			),
+		),
+	),
+);
\ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php
new file mode 100644
index 0000000..5196e9a
--- /dev/null
+++ b/tests/mocks/database/config/pdo/pgsql.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+	
+	// Typical Database configuration
+	'pdo/pgsql' => array(
+		'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+		'hostname' => 'localhost',
+		'username' => 'postgres',
+		'password' => '',
+		'database' => 'ci_test',
+		'dbdriver' => 'pdo',
+		'pdodriver' => 'pgsql',
+	),
+
+	// Database configuration with failover
+	'pdo/pgsql_failover' => array(
+		'dsn' => '',
+		'hostname' => 'localhost',
+		'username' => 'not_travis',
+		'password' => 'wrong password',
+		'database' => 'not_ci_test',
+		'dbdriver' => 'pdo',
+		'pdodriver' => 'pgsql',
+		'failover' => array(
+			array(
+				'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;',
+				'hostname' => 'localhost',
+				'username' => 'postgres',
+				'password' => '',
+				'database' => 'ci_test',
+				'dbdriver' => 'pdo',
+				'pdodriver' => 'pgsql',
+			),
+		),
+	),
+);
\ No newline at end of file
diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php
new file mode 100644
index 0000000..c68b4b2
--- /dev/null
+++ b/tests/mocks/database/config/pdo/sqlite.php
@@ -0,0 +1,37 @@
+<?php
+
+return array(
+
+	// Typical Database configuration
+	'pdo/sqlite' => array(
+		'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+		'hostname' => 'localhost',
+		'username' => 'sqlite',
+		'password' => 'sqlite',
+		'database' => 'sqlite',
+		'dbdriver' => 'pdo',
+		'pdodriver' => 'sqlite',
+	),
+
+	// Database configuration with failover
+	'pdo/sqlite_failover' => array(
+		'dsn' => 'sqlite:not_exists.sqlite',
+		'hostname' => 'localhost',
+		'username' => 'sqlite',
+		'password' => 'sqlite',
+		'database' => 'sqlite',
+		'dbdriver' => 'pdo',
+		'pdodriver' => 'sqlite',
+		'failover' => array(
+			array(
+				'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite',
+				'hostname' => 'localhost',
+				'username' => 'sqlite',
+				'password' => 'sqlite',
+				'database' => 'sqlite',
+				'dbdriver' => 'pdo', 
+				'pdodriver' => 'sqlite',
+			),
+		),
+	),
+);
\ No newline at end of file
diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php
index 8665e20..755ce2a 100644
--- a/tests/mocks/database/config/sqlite.php
+++ b/tests/mocks/database/config/sqlite.php
@@ -1,5 +1,4 @@
 <?php
-$dbdriver = is_php('5.4') ? 'sqlite3' : 'sqlite';
 
 return array(
 
@@ -10,7 +9,7 @@
 		'username' => 'sqlite',
 		'password' => 'sqlite',
 		'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
-		'dbdriver' => $dbdriver,
+		'dbdriver' => 'sqlite3',
 	),
 
 	// Database configuration with failover
@@ -20,15 +19,15 @@
 		'username' => 'sqlite',
 		'password' => 'sqlite',
 		'database' => '../not_exists.sqlite',
-		'dbdriver' => $dbdriver,
+		'dbdriver' => 'sqlite3',
 		'failover' => array(
 			array(
 				'dsn' => '',
 				'hostname' => 'localhost',
 				'username' => 'sqlite',
 				'password' => 'sqlite',
-				'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite',
-				'dbdriver' => $dbdriver,
+				'database' => realpath(__DIR__.'/..').'/ci_test.sqlite',
+				'dbdriver' => 'sqlite3',
 			),
 		),
 	),
diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php
index 43a0d39..59028ed 100644
--- a/tests/mocks/database/db.php
+++ b/tests/mocks/database/db.php
@@ -45,19 +45,18 @@
 		);
 
 		$config = array_merge($this->config[$group], $params);
+		$dsnstring = ( ! empty($config['dsn'])) ? $config['dsn'] : FALSE;
+		$pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE;
+		$failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE;
 
-		if ( ! empty($config['dsn']))
-		{
-			$dsn = $config['dsn'];
-		}
-		else
-		{
-			$dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
+		$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 ($pdodriver) $other_params['pdodriver'] = $pdodriver;
+		if ($failover) $other_params['failover'] = $failover;
 
 		return $dsn.'?'.http_build_query($other_params);
 	}
diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php
new file mode 100644
index 0000000..cb18202
--- /dev/null
+++ b/tests/mocks/database/db/driver.php
@@ -0,0 +1,36 @@
+<?php
+
+class Mock_Database_DB_Driver extends CI_DB_driver {
+	
+	/**
+	 * @var object The actual Driver
+	 */
+	protected $ci_db_driver;
+
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($driver_class, $config = array())
+	{
+		if (is_string($driver_class)) $this->ci_db_driver = new $driver_class($config);
+	}
+
+	/**
+	 * Overloading method, emulate the actual driver method (multiple inheritance workaround)
+	 */
+	public function __call($method, $arguments)
+	{
+		if ( ! is_callable(array($this->ci_db_driver, $method)))
+		{
+			throw new BadMethodCallException($method. ' not exists or not implemented');
+		}
+
+		return call_user_func_array(array($this->ci_db_driver, $method), $arguments);
+	}
+}
+
+class CI_DB extends Mock_Database_DB_QueryBuilder {}
\ No newline at end of file
diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php
new file mode 100644
index 0000000..1b95c92
--- /dev/null
+++ b/tests/mocks/database/db/querybuilder.php
@@ -0,0 +1,10 @@
+<?php
+
+if ( ! class_exists('CI_DB_query_builder'))
+{
+	class Mock_Database_DB_QueryBuilder extends CI_DB_active_record {}
+}
+else
+{
+	class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {}
+}
diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php
new file mode 100644
index 0000000..34a74e2
--- /dev/null
+++ b/tests/mocks/database/drivers/mysql.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_mysql_driver', $config);
+	}
+}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php
new file mode 100644
index 0000000..590e195
--- /dev/null
+++ b/tests/mocks/database/drivers/pdo.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_pdo_driver', $config);
+	}
+}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php
new file mode 100644
index 0000000..0df9059
--- /dev/null
+++ b/tests/mocks/database/drivers/postgre.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_postgre_driver', $config);
+	}
+}
\ No newline at end of file
diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php
new file mode 100644
index 0000000..76a182c
--- /dev/null
+++ b/tests/mocks/database/drivers/sqlite.php
@@ -0,0 +1,16 @@
+<?php
+
+class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver {
+	
+	/**
+	 * Instantiate the database driver
+	 *
+	 * @param  string 	DB Driver class name
+	 * @param  array 	DB configuration to set
+	 * @return void
+	 */
+	public function __construct($config = array())
+	{
+		parent::__construct('CI_DB_sqlite3_driver', $config);
+	}
+}
\ No newline at end of file
diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep
deleted file mode 100644
index e69de29..0000000
--- a/tests/mocks/database/schema/.gitkeep
+++ /dev/null
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
new file mode 100644
index 0000000..a3d5bac
--- /dev/null
+++ b/tests/mocks/database/schema/skeleton.php
@@ -0,0 +1,98 @@
+<?php
+
+class Mock_Database_Schema_Skeleton {
+
+	/**
+	 * @var object Database Holder
+	 */
+	public static $db;
+
+	/**
+	 * @var object Forge Holder
+	 */
+	public static $forge;
+
+	/**
+	 * @var object Driver Holder
+	 */
+	public static $driver;
+
+	/**
+	 * Initialize both database and forge components
+	 */
+	public static function init($driver)
+	{
+		if (empty(static::$db) && empty(static::$forge))
+		{
+			$config = Mock_Database_DB::config($driver);
+			$connection = new Mock_Database_DB($config);
+			$db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE);
+
+			CI_TestCase::instance()->ci_instance_var('db', $db);
+
+			$loader = new Mock_Core_Loader();
+			$loader->dbforge();
+			$forge = CI_TestCase::instance()->ci_instance_var('dbforge');
+
+			static::$db = $db;
+			static::$forge = $forge;
+			static::$driver = $driver;
+		}
+
+		return static::$db;
+	}
+	
+	
+	/**
+	 * Create the dummy tables
+	 *
+	 * @return void
+	 */
+	public static function create_tables()
+	{
+		// Job Table
+		static::$forge->add_field(array(
+			'id' => array(
+				'type' => 'INTEGER',
+				'constraint' => 3,
+			),
+			'name' => array(
+				'type' => 'VARCHAR',
+				'constraint' => 40,
+			),
+			'description' => array(
+				'type' => 'TEXT',
+			),
+		));
+		static::$forge->add_key('id', TRUE);
+		static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+	}
+
+	/**
+	 * Create the dummy datas
+	 *
+	 * @return void
+	 */
+	public static function create_data()
+	{
+		// Job Data
+		$data = array(
+			'job' => array(
+				array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), 
+				array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
+    			array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
+			    array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
+			),
+		);
+
+		foreach ($data as $table => $dummy_data) 
+		{
+			static::$db->truncate($table);
+
+			foreach ($dummy_data as $single_dummy_data)
+			{
+				static::$db->insert($table, $single_dummy_data); 
+			}
+		}
+	}
+}
\ No newline at end of file
diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml
index 44d6d6e..e9556f7 100644
--- a/tests/travis/mysql.phpunit.xml
+++ b/tests/travis/mysql.phpunit.xml
@@ -28,10 +28,5 @@
 			<directory suffix=".php">PROJECT_BASE.'tests'</directory>
 			<directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
 		</blacklist>
-		<whitelist>
-			<!--
-			<directory suffix=".php">'../system/core'</directory>
-			-->
-		</whitelist>
 	</filters>
 </phpunit>
\ No newline at end of file
diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml
new file mode 100644
index 0000000..69eece2
--- /dev/null
+++ b/tests/travis/pdo/mysql.phpunit.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit 
+	bootstrap="../../Bootstrap.php"
+	colors="true"
+	convertNoticesToExceptions="true"
+	convertWarningsToExceptions="true"
+	stopOnError="false"
+	stopOnFailure="false"
+	stopOnIncomplete="false"
+	stopOnSkipped="false">
+	<php>
+        <const name="DB_DRIVER" value="pdo/mysql"/>
+    </php>
+	<testsuites>
+		<testsuite name="CodeIgniter Core Test Suite">
+			<file>../../codeigniter/Setup_test.php</file>
+			<directory suffix="test.php">../../codeigniter/core</directory>
+			<directory suffix="test.php">../../codeigniter/helpers</directory>
+			<directory suffix="test.php">../../codeigniter/libraries</directory>
+			<directory suffix="test.php">../../codeigniter/database</directory>
+		</testsuite>
+	</testsuites>
+	<filters>
+		<blacklist>
+			<directory suffix=".php">PEAR_INSTALL_DIR</directory>
+			<directory suffix=".php">PHP_LIBDIR</directory>
+			<directory suffix=".php">PROJECT_BASE.'tests'</directory>
+			<directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
+		</blacklist>
+	</filters>
+</phpunit>
\ No newline at end of file
diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml
new file mode 100644
index 0000000..e68c3e0
--- /dev/null
+++ b/tests/travis/pdo/pgsql.phpunit.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit 
+	bootstrap="../../Bootstrap.php"
+	colors="true"
+	convertNoticesToExceptions="true"
+	convertWarningsToExceptions="true"
+	stopOnError="false"
+	stopOnFailure="false"
+	stopOnIncomplete="false"
+	stopOnSkipped="false">
+	<php>
+        <const name="DB_DRIVER" value="pdo/pgsql"/>
+    </php>
+	<testsuites>
+		<testsuite name="CodeIgniter Core Test Suite">
+			<file>../../codeigniter/Setup_test.php</file>
+			<directory suffix="test.php">../../codeigniter/core</directory>
+			<directory suffix="test.php">../../codeigniter/helpers</directory>
+			<directory suffix="test.php">../../codeigniter/libraries</directory>
+			<directory suffix="test.php">../../codeigniter/database</directory>
+		</testsuite>
+	</testsuites>
+	<filters>
+		<blacklist>
+			<directory suffix=".php">PEAR_INSTALL_DIR</directory>
+			<directory suffix=".php">PHP_LIBDIR</directory>
+			<directory suffix=".php">PROJECT_BASE.'tests'</directory>
+			<directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
+		</blacklist>
+	</filters>
+</phpunit>
\ No newline at end of file
diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml
new file mode 100644
index 0000000..1871f62
--- /dev/null
+++ b/tests/travis/pdo/sqlite.phpunit.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit 
+	bootstrap="../../Bootstrap.php"
+	colors="true"
+	convertNoticesToExceptions="true"
+	convertWarningsToExceptions="true"
+	stopOnError="false"
+	stopOnFailure="false"
+	stopOnIncomplete="false"
+	stopOnSkipped="false">
+	<php>
+        <const name="DB_DRIVER" value="pdo/sqlite"/>
+    </php>
+	<testsuites>
+		<testsuite name="CodeIgniter Core Test Suite">
+			<file>../../codeigniter/Setup_test.php</file>
+			<directory suffix="test.php">../../codeigniter/core</directory>
+			<directory suffix="test.php">../../codeigniter/helpers</directory>
+			<directory suffix="test.php">../../codeigniter/libraries</directory>
+			<directory suffix="test.php">../../codeigniter/database</directory>
+		</testsuite>
+	</testsuites>
+	<filters>
+		<blacklist>
+			<directory suffix=".php">PEAR_INSTALL_DIR</directory>
+			<directory suffix=".php">PHP_LIBDIR</directory>
+			<directory suffix=".php">PROJECT_BASE.'tests'</directory>
+			<directory suffix=".php">'../../../system/core/CodeIgniter.php'</directory>
+		</blacklist>
+	</filters>
+</phpunit>
\ No newline at end of file
diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml
index 9f52b40..ad8aede 100644
--- a/tests/travis/pgsql.phpunit.xml
+++ b/tests/travis/pgsql.phpunit.xml
@@ -28,10 +28,5 @@
 			<directory suffix=".php">PROJECT_BASE.'tests'</directory>
 			<directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
 		</blacklist>
-		<whitelist>
-			<!--
-			<directory suffix=".php">'../system/core'</directory>
-			-->
-		</whitelist>
 	</filters>
 </phpunit>
\ No newline at end of file
diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml
index 74ebb48..628370e 100644
--- a/tests/travis/sqlite.phpunit.xml
+++ b/tests/travis/sqlite.phpunit.xml
@@ -28,10 +28,5 @@
 			<directory suffix=".php">PROJECT_BASE.'tests'</directory>
 			<directory suffix=".php">'../../system/core/CodeIgniter.php'</directory>
 		</blacklist>
-		<whitelist>
-			<!--
-			<directory suffix=".php">'../system/core'</directory>
-			-->
-		</whitelist>
 	</filters>
 </phpunit>
\ No newline at end of file