From f4c6c9b3061b464c959b6409f962228959f35287 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 23:24:09 +0700 Subject: DB Drivers test --- tests/mocks/database/config/ci_test.sqlite | 0 tests/mocks/database/config/pdo/sqlite.php | 3 +++ tests/mocks/database/db.php | 6 +++++ tests/mocks/database/db/driver.php | 36 ++++++++++++++++++++++++++++++ tests/mocks/database/drivers/mysql.php | 16 +++++++++++++ tests/mocks/database/drivers/pdo.php | 16 +++++++++++++ tests/mocks/database/drivers/postgre.php | 16 +++++++++++++ tests/mocks/database/drivers/sqlite.php | 16 +++++++++++++ 8 files changed, 109 insertions(+) create mode 100644 tests/mocks/database/config/ci_test.sqlite create mode 100644 tests/mocks/database/db/driver.php create mode 100644 tests/mocks/database/drivers/mysql.php create mode 100644 tests/mocks/database/drivers/pdo.php create mode 100644 tests/mocks/database/drivers/postgre.php create mode 100644 tests/mocks/database/drivers/sqlite.php (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/config/ci_test.sqlite b/tests/mocks/database/config/ci_test.sqlite new file mode 100644 index 000000000..e69de29bb diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php index c6827b41c..1e5043b00 100644 --- a/tests/mocks/database/config/pdo/sqlite.php +++ b/tests/mocks/database/config/pdo/sqlite.php @@ -6,16 +6,19 @@ return array( 'pdo/sqlite' => array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', 'dbdriver' => 'pdo', + 'pdodriver' => 'sqlite', ), // Database configuration with failover 'pdo/sqlite_failover' => array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite', 'dbdriver' => 'pdo', + 'pdodriver' => 'sqlite', 'failover' => array( array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', 'dbdriver' => 'pdo', + 'pdodriver' => 'sqlite', ), ), ), diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index 43a0d391f..c30e6d2e6 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -45,6 +45,8 @@ class Mock_Database_DB { ); $config = array_merge($this->config[$group], $params); + $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE; + $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE; if ( ! empty($config['dsn'])) { @@ -57,7 +59,11 @@ class Mock_Database_DB { } + // Build the parameter $other_params = array_slice($config, 6); + $other_params['dsn'] = $dsn; + 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 000000000..9bf5231e3 --- /dev/null +++ b/tests/mocks/database/db/driver.php @@ -0,0 +1,36 @@ +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 CI_DB_Driver {} \ No newline at end of file diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php new file mode 100644 index 000000000..34a74e2bf --- /dev/null +++ b/tests/mocks/database/drivers/mysql.php @@ -0,0 +1,16 @@ +