From ac5373a8979537f5454af6b911108541140a35d7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:03:38 +0700 Subject: Adding core and libraries mock classes --- tests/mocks/database/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/mocks/database/.gitkeep (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/.gitkeep b/tests/mocks/database/.gitkeep new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3-24-g4f1b From 655a89f4059ebae017d1c4ec5f26aeb2cf4a3bae Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 29 Mar 2012 03:00:56 +0700 Subject: Preliminary Database Test --- tests/mocks/database/.gitkeep | 0 tests/mocks/database/db.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) delete mode 100644 tests/mocks/database/.gitkeep create mode 100644 tests/mocks/database/db.php (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/.gitkeep b/tests/mocks/database/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php new file mode 100644 index 000000000..d7a6351a0 --- /dev/null +++ b/tests/mocks/database/db.php @@ -0,0 +1,43 @@ +config = $config; + } + + public function set_config($group = 'default') + { + if ( ! isset($this->config[$group])) + { + throw new InvalidArgumentException('Group '.$group.' not exists'); + } + + if ( ! empty($this->config[$group]['dsn'])) + { + $dsn = $this->config[$group]['dsn']; + } + else + { + $config = $this->config[$group]; + $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] + .'@'.$config['hostname'].'/'.$config['database']; + + } + + $params = array_slice($this->config[$group], 6); + + return $dsn.http_build_query($params); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a8a2e3325c128ccdc941daba3bba10b78bf2d098 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 29 Mar 2012 03:56:46 +0700 Subject: Travis setup and minor cleanup --- tests/mocks/database/db.php | 45 +++++++++++++++++++++++++++++------- tests/mocks/database/models/.gitkeep | 0 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 tests/mocks/database/models/.gitkeep (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index d7a6351a0..11e4a93bd 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -12,32 +12,61 @@ class Mock_Database_DB { */ public function __construct($config = array()) { - include_once(BASEPATH.'database/DB.php'); - $this->config = $config; } - public function set_config($group = 'default') + public function set_dsn($group = 'default') { if ( ! isset($this->config[$group])) { throw new InvalidArgumentException('Group '.$group.' not exists'); } - if ( ! empty($this->config[$group]['dsn'])) + $params = array( + 'dbprefix' => '', + 'pconnect' => FALSE, + 'db_debug' => TRUE, + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'autoinit' => TRUE, + 'stricton' => FALSE, + 'failover' => array() + ); + + $config = array_merge($this->config[$group], $params); + + if ( ! empty($config['dsn'])) { - $dsn = $this->config[$group]['dsn']; + $dsn = $config['dsn']; } else { - $config = $this->config[$group]; $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] .'@'.$config['hostname'].'/'.$config['database']; } - $params = array_slice($this->config[$group], 6); + $other_params = array_slice($config, 6); + + return $dsn.http_build_query($other_params); + } + + public static function DB($group, $query_builder = FALSE) + { + include_once(BASEPATH.'database/DB.php'); + + try + { + $db = DB($group, $query_builder); + } + catch (Exception $e) + { + throw new InvalidArgumentException($e->getMessage()); + } - return $dsn.http_build_query($params); + return $db; } } \ No newline at end of file diff --git a/tests/mocks/database/models/.gitkeep b/tests/mocks/database/models/.gitkeep new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3-24-g4f1b From dba9437218a5d8bedb75464b943e8f920d220a25 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 29 Mar 2012 04:09:37 +0700 Subject: Add schema folder --- tests/mocks/database/models/.gitkeep | 0 tests/mocks/database/schema/.gitkeep | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/mocks/database/models/.gitkeep create mode 100644 tests/mocks/database/schema/.gitkeep (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/models/.gitkeep b/tests/mocks/database/models/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.3-24-g4f1b From ee2f5d08c64d96b7abc7195bcd1b6a3fd67b5b42 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 30 Mar 2012 06:29:11 +0700 Subject: Multi database setup --- tests/mocks/database/ci_test.sqlite | Bin 0 -> 17408 bytes tests/mocks/database/config/mysql.php | 34 ++++++++++++++++++++++++++++++++ tests/mocks/database/config/pgsql.php | 34 ++++++++++++++++++++++++++++++++ tests/mocks/database/config/sqlite.php | 34 ++++++++++++++++++++++++++++++++ tests/mocks/database/db.php | 35 ++++++++++++++++++++++++++++++--- 5 files changed, 134 insertions(+), 3 deletions(-) create mode 100755 tests/mocks/database/ci_test.sqlite create mode 100644 tests/mocks/database/config/mysql.php create mode 100644 tests/mocks/database/config/pgsql.php create mode 100644 tests/mocks/database/config/sqlite.php (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite new file mode 100755 index 000000000..37ce4f870 Binary files /dev/null and b/tests/mocks/database/ci_test.sqlite differ diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php new file mode 100644 index 000000000..ace0a31b1 --- /dev/null +++ b/tests/mocks/database/config/mysql.php @@ -0,0 +1,34 @@ + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + ), + + // Database configuration with failover + 'mysql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'mysql', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + ), + ), + ), +); \ No newline at end of file diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php new file mode 100644 index 000000000..c06af8ce0 --- /dev/null +++ b/tests/mocks/database/config/pgsql.php @@ -0,0 +1,34 @@ + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'postgre', + ), + + // Database configuration with failover + 'pgsql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'postgre', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'postgre', + ), + ), + ), +); \ No newline at end of file diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php new file mode 100644 index 000000000..cf428f473 --- /dev/null +++ b/tests/mocks/database/config/sqlite.php @@ -0,0 +1,34 @@ + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dbdriver' => 'sqlite', + ), + + // Database configuration with failover + 'sqlite_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => '../not_exists.sqlite', + 'dbdriver' => 'sqlite', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', + 'dbdriver' => 'sqlite', + ), + ), + ), +); \ No newline at end of file diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index 11e4a93bd..43a0d391f 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -2,6 +2,9 @@ class Mock_Database_DB { + /** + * @var array DB configuration + */ private $config = array(); /** @@ -15,6 +18,12 @@ class Mock_Database_DB { $this->config = $config; } + /** + * Build DSN connection string for DB driver instantiate process + * + * @param string Group name + * @return string DSN Connection string + */ public function set_dsn($group = 'default') { if ( ! isset($this->config[$group])) @@ -25,7 +34,7 @@ class Mock_Database_DB { $params = array( 'dbprefix' => '', 'pconnect' => FALSE, - 'db_debug' => TRUE, + 'db_debug' => FALSE, 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', @@ -33,7 +42,6 @@ class Mock_Database_DB { 'swap_pre' => '', 'autoinit' => TRUE, 'stricton' => FALSE, - 'failover' => array() ); $config = array_merge($this->config[$group], $params); @@ -51,9 +59,30 @@ class Mock_Database_DB { $other_params = array_slice($config, 6); - return $dsn.http_build_query($other_params); + return $dsn.'?'.http_build_query($other_params); } + /** + * Return a database config array + * + * @see ./config + * @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 + */ public static function DB($group, $query_builder = FALSE) { include_once(BASEPATH.'database/DB.php'); -- cgit v1.2.3-24-g4f1b From 6dfe76dfe4634971faeef197aa724c924a72d515 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 12:42:59 +0300 Subject: Alter SQLite tests config to use the sqlite3 driver under PHP 5.4+ --- tests/mocks/database/config/sqlite.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php index cf428f473..8665e208d 100644 --- a/tests/mocks/database/config/sqlite.php +++ b/tests/mocks/database/config/sqlite.php @@ -1,7 +1,8 @@ array( 'dsn' => '', @@ -9,7 +10,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', - 'dbdriver' => 'sqlite', + 'dbdriver' => $dbdriver, ), // Database configuration with failover @@ -19,7 +20,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => '../not_exists.sqlite', - 'dbdriver' => 'sqlite', + 'dbdriver' => $dbdriver, 'failover' => array( array( 'dsn' => '', @@ -27,7 +28,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', - 'dbdriver' => 'sqlite', + 'dbdriver' => $dbdriver, ), ), ), -- cgit v1.2.3-24-g4f1b From 44015c8d91ecea78ee4a10de579c36a859c2fcb6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 19:38:16 +0700 Subject: Set up PDO constant and configuration --- tests/mocks/database/config/pdo/mysql.php | 37 ++++++++++++++++++++++++++++++ tests/mocks/database/config/pdo/pgsql.php | 37 ++++++++++++++++++++++++++++++ tests/mocks/database/config/pdo/sqlite.php | 22 ++++++++++++++++++ tests/mocks/database/config/sqlite.php | 7 +++--- 4 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 tests/mocks/database/config/pdo/mysql.php create mode 100644 tests/mocks/database/config/pdo/pgsql.php create mode 100644 tests/mocks/database/config/pdo/sqlite.php (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php new file mode 100644 index 000000000..cefb6b008 --- /dev/null +++ b/tests/mocks/database/config/pdo/mysql.php @@ -0,0 +1,37 @@ + 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 000000000..b2f409d8d --- /dev/null +++ b/tests/mocks/database/config/pdo/pgsql.php @@ -0,0 +1,37 @@ + array( + 'dsn' => '', + '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' => '', + '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 000000000..c6827b41c --- /dev/null +++ b/tests/mocks/database/config/pdo/sqlite.php @@ -0,0 +1,22 @@ + array( + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dbdriver' => 'pdo', + ), + + // Database configuration with failover + 'pdo/sqlite_failover' => array( + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/not_exists.sqlite', + 'dbdriver' => 'pdo', + 'failover' => array( + array( + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dbdriver' => 'pdo', + ), + ), + ), +); \ No newline at end of file diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php index 8665e208d..c70986e7c 100644 --- a/tests/mocks/database/config/sqlite.php +++ b/tests/mocks/database/config/sqlite.php @@ -1,5 +1,4 @@ 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', - 'dbdriver' => $dbdriver, + 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', ), // Database configuration with failover @@ -20,7 +19,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => '../not_exists.sqlite', - 'dbdriver' => $dbdriver, + 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', 'failover' => array( array( 'dsn' => '', @@ -28,7 +27,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', - 'dbdriver' => $dbdriver, + 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', ), ), ), -- cgit v1.2.3-24-g4f1b 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 @@ + Date: Wed, 4 Apr 2012 23:46:23 +0700 Subject: Fix sqlite issue on PHP 5.4 both for native and PDO driver --- tests/mocks/database/config/ci_test.sqlite | 0 tests/mocks/database/config/pdo/sqlite.php | 20 ++++++++++++++++---- tests/mocks/database/db.php | 13 +++---------- 3 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 tests/mocks/database/config/ci_test.sqlite (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/config/ci_test.sqlite b/tests/mocks/database/config/ci_test.sqlite deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php index 1e5043b00..c68b4b213 100644 --- a/tests/mocks/database/config/pdo/sqlite.php +++ b/tests/mocks/database/config/pdo/sqlite.php @@ -4,20 +4,32 @@ return array( // Typical Database configuration 'pdo/sqlite' => array( - 'dsn' => 'sqlite:/'.realpath(__DIR__.'/..').'/ci_test.sqlite', + '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:/'.realpath(__DIR__.'/..').'/not_exists.sqlite', + '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', - 'dbdriver' => 'pdo', + 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => 'sqlite', + 'dbdriver' => 'pdo', 'pdodriver' => 'sqlite', ), ), diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index c30e6d2e6..59028ed9c 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -45,23 +45,16 @@ class Mock_Database_DB { ); $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); - $other_params['dsn'] = $dsn; + if ($dsnstring) $other_params['dsn'] = $dsnstring; if ($pdodriver) $other_params['pdodriver'] = $pdodriver; if ($failover) $other_params['failover'] = $failover; -- cgit v1.2.3-24-g4f1b From 26490e37f4bdb267b71431abd79782549cbbadda Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 23:50:00 +0700 Subject: Add branch to travis list --- tests/mocks/database/drivers/sqlite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php index 49c68c50f..76a182cbf 100644 --- a/tests/mocks/database/drivers/sqlite.php +++ b/tests/mocks/database/drivers/sqlite.php @@ -11,6 +11,6 @@ class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver { */ public function __construct($config = array()) { - parent::__construct('CI_DB_sqlite_driver', $config); + parent::__construct('CI_DB_sqlite3_driver', $config); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 61ff054fb905f0514b942bf3e70a6c882bd64f7a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:23:56 +0700 Subject: Adding schema and initial Query Builder code coverage --- tests/mocks/database/ci_test.sqlite | Bin 17408 -> 17408 bytes tests/mocks/database/config/sqlite.php | 6 +++--- tests/mocks/database/db/driver.php | 2 +- tests/mocks/database/schema/.gitkeep | 0 4 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 tests/mocks/database/schema/.gitkeep (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index 37ce4f870..86d868af2 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php index c70986e7c..75fdacd96 100644 --- a/tests/mocks/database/config/sqlite.php +++ b/tests/mocks/database/config/sqlite.php @@ -9,7 +9,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', - 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', + 'dbdriver' => 'sqlite3', ), // Database configuration with failover @@ -19,7 +19,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => '../not_exists.sqlite', - 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', + 'dbdriver' => 'sqlite3', 'failover' => array( array( 'dsn' => '', @@ -27,7 +27,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', - 'dbdriver' => is_php('5.4') ? 'sqlite3' : 'sqlite', + 'dbdriver' => 'sqlite3', ), ), ), diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php index 9bf5231e3..cb1820277 100644 --- a/tests/mocks/database/db/driver.php +++ b/tests/mocks/database/db/driver.php @@ -33,4 +33,4 @@ class Mock_Database_DB_Driver extends CI_DB_driver { } } -class CI_DB extends CI_DB_Driver {} \ No newline at end of file +class CI_DB extends Mock_Database_DB_QueryBuilder {} \ 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 e69de29bb..000000000 -- cgit v1.2.3-24-g4f1b From 5b421665bac7609192917f7b0f34838534be099e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:24:50 +0700 Subject: Simple query builder tests --- tests/mocks/database/db/querybuilder.php | 10 +++++ tests/mocks/database/schema/skeleton.php | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/mocks/database/db/querybuilder.php create mode 100644 tests/mocks/database/schema/skeleton.php (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php new file mode 100644 index 000000000..1b95c92af --- /dev/null +++ b/tests/mocks/database/db/querybuilder.php @@ -0,0 +1,10 @@ +add_field(array( + 'id' => array( + 'type' => 'INT', + 'constraint' => 3, + ), + 'name' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), + 'description' => array( + 'type' => 'TEXT', + 'constraint' => 0, + ), + )); + $forge->add_key('id', TRUE); + $forge->create_table('job', TRUE); + } + + /** + * Create the dummy datas + * + * @return void + */ + public static function create_data($db) + { + // 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) + { + $db->truncate($table); + + if (strpos(DB_DRIVER, 'sqlite') === FALSE) + { + $db->insert_batch($table, $dummy_data); + } + else + { + foreach ($dummy_data as $single_dummy_data) + { + $db->insert($table, $single_dummy_data); + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 55f804239cb0141fdac748607d8cdfa143efac92 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:48:52 +0700 Subject: Add dsn to pgsql --- tests/mocks/database/config/pdo/pgsql.php | 4 ++-- tests/mocks/database/config/sqlite.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php index b2f409d8d..5196e9ad9 100644 --- a/tests/mocks/database/config/pdo/pgsql.php +++ b/tests/mocks/database/config/pdo/pgsql.php @@ -4,7 +4,7 @@ return array( // Typical Database configuration 'pdo/pgsql' => array( - 'dsn' => '', + 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', 'hostname' => 'localhost', 'username' => 'postgres', 'password' => '', @@ -24,7 +24,7 @@ return array( 'pdodriver' => 'pgsql', 'failover' => array( array( - 'dsn' => '', + 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', 'hostname' => 'localhost', 'username' => 'postgres', 'password' => '', diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php index 75fdacd96..755ce2a3a 100644 --- a/tests/mocks/database/config/sqlite.php +++ b/tests/mocks/database/config/sqlite.php @@ -26,7 +26,7 @@ return array( 'hostname' => 'localhost', 'username' => 'sqlite', 'password' => 'sqlite', - 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', 'dbdriver' => 'sqlite3', ), ), -- cgit v1.2.3-24-g4f1b From 024098d05d00383bf82165e1f8bbadb53cbcaa9b Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 01:51:57 +0700 Subject: Use more user-friendly method for dummy create data --- tests/mocks/database/schema/skeleton.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index bf9e75b45..53df73bdd 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -48,17 +48,10 @@ class Mock_Database_Schema_Skeleton { foreach ($data as $table => $dummy_data) { $db->truncate($table); - - if (strpos(DB_DRIVER, 'sqlite') === FALSE) - { - $db->insert_batch($table, $dummy_data); - } - else + + foreach ($dummy_data as $single_dummy_data) { - foreach ($dummy_data as $single_dummy_data) - { - $db->insert($table, $single_dummy_data); - } + $db->insert($table, $single_dummy_data); } } } -- cgit v1.2.3-24-g4f1b From 1bfc0d9a2b47be1a2a0b8efda60ebdd9d7a303dd Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 02:25:25 +0700 Subject: Fix postgre table datatype --- tests/mocks/database/schema/skeleton.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 53df73bdd..47e8bfd35 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -12,7 +12,7 @@ class Mock_Database_Schema_Skeleton { // Job Table $forge->add_field(array( 'id' => array( - 'type' => 'INT', + 'type' => 'INTEGER', 'constraint' => 3, ), 'name' => array( @@ -21,11 +21,11 @@ class Mock_Database_Schema_Skeleton { ), 'description' => array( 'type' => 'TEXT', - 'constraint' => 0, ), )); $forge->add_key('id', TRUE); - $forge->create_table('job', TRUE); + $res = $forge->create_table('job'); + var_dump($res); } /** -- cgit v1.2.3-24-g4f1b From b0703b0bee89ab0eae83bae78daad5c5a3504043 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 02:31:52 +0700 Subject: Resolve postgres issue on create table --- tests/mocks/database/schema/skeleton.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 47e8bfd35..6610d6b59 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -7,7 +7,7 @@ class Mock_Database_Schema_Skeleton { * * @return void */ - public static function create_tables($forge) + public static function create_tables($forge, $driver) { // Job Table $forge->add_field(array( @@ -24,8 +24,7 @@ class Mock_Database_Schema_Skeleton { ), )); $forge->add_key('id', TRUE); - $res = $forge->create_table('job'); - var_dump($res); + $forge->create_table('job', (strpos($driver, 'pgsql') === FALSE)); } /** -- cgit v1.2.3-24-g4f1b From 55f622f76371949ae615ccdff76ed1e4bab55170 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 19:01:34 +0700 Subject: Add select clause test --- tests/mocks/database/schema/skeleton.php | 55 ++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'tests/mocks/database') diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 6610d6b59..a3d5bac65 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -1,16 +1,57 @@ 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($forge, $driver) + public static function create_tables() { // Job Table - $forge->add_field(array( + static::$forge->add_field(array( 'id' => array( 'type' => 'INTEGER', 'constraint' => 3, @@ -23,8 +64,8 @@ class Mock_Database_Schema_Skeleton { 'type' => 'TEXT', ), )); - $forge->add_key('id', TRUE); - $forge->create_table('job', (strpos($driver, 'pgsql') === FALSE)); + static::$forge->add_key('id', TRUE); + static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE)); } /** @@ -32,7 +73,7 @@ class Mock_Database_Schema_Skeleton { * * @return void */ - public static function create_data($db) + public static function create_data() { // Job Data $data = array( @@ -46,11 +87,11 @@ class Mock_Database_Schema_Skeleton { foreach ($data as $table => $dummy_data) { - $db->truncate($table); + static::$db->truncate($table); foreach ($dummy_data as $single_dummy_data) { - $db->insert($table, $single_dummy_data); + static::$db->insert($table, $single_dummy_data); } } } -- cgit v1.2.3-24-g4f1b