From 6a96bf7ece4da23e2a802f48c408fa240da776f0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 4 Apr 2012 19:13:03 +0700 Subject: Include PDO code coverage, remove unnecessary line on phpunit xml --- tests/travis/mysql.phpunit.xml | 5 ----- tests/travis/pdo/mysql.phpunit.xml | 32 ++++++++++++++++++++++++++++++++ tests/travis/pdo/pgsql.phpunit.xml | 32 ++++++++++++++++++++++++++++++++ tests/travis/pdo/sqlite.phpunit.xml | 32 ++++++++++++++++++++++++++++++++ tests/travis/pgsql.phpunit.xml | 5 ----- tests/travis/sqlite.phpunit.xml | 5 ----- 6 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 tests/travis/pdo/mysql.phpunit.xml create mode 100644 tests/travis/pdo/pgsql.phpunit.xml create mode 100644 tests/travis/pdo/sqlite.phpunit.xml (limited to 'tests') diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index 44d6d6ed9..e9556f758 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -28,10 +28,5 @@ PROJECT_BASE.'tests' '../../system/core/CodeIgniter.php' - - - \ 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 000000000..eb650fa1e --- /dev/null +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -0,0 +1,32 @@ + + + + + + + + + ../../codeigniter/Setup_test.php + ../../codeigniter/core + ../../codeigniter/helpers + ../../codeigniter/libraries + ../../codeigniter/database + + + + + PEAR_INSTALL_DIR + PHP_LIBDIR + PROJECT_BASE.'tests' + '../../../system/core/CodeIgniter.php' + + + \ 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 000000000..351f690d5 --- /dev/null +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -0,0 +1,32 @@ + + + + + + + + + ../../codeigniter/Setup_test.php + ../../codeigniter/core + ../../codeigniter/helpers + ../../codeigniter/libraries + ../../codeigniter/database + + + + + PEAR_INSTALL_DIR + PHP_LIBDIR + PROJECT_BASE.'tests' + '../../../system/core/CodeIgniter.php' + + + \ 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 000000000..ae139b7a9 --- /dev/null +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -0,0 +1,32 @@ + + + + + + + + + ../../codeigniter/Setup_test.php + ../../codeigniter/core + ../../codeigniter/helpers + ../../codeigniter/libraries + ../../codeigniter/database + + + + + PEAR_INSTALL_DIR + PHP_LIBDIR + PROJECT_BASE.'tests' + '../../../system/core/CodeIgniter.php' + + + \ No newline at end of file diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index 9f52b40ae..ad8aeded2 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -28,10 +28,5 @@ PROJECT_BASE.'tests' '../../system/core/CodeIgniter.php' - - - \ No newline at end of file diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 74ebb482b..628370e93 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -28,10 +28,5 @@ PROJECT_BASE.'tests' '../../system/core/CodeIgniter.php' - - - \ No newline at end of file -- 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 +++--- tests/travis/pdo/mysql.phpunit.xml | 2 +- tests/travis/pdo/pgsql.phpunit.xml | 2 +- tests/travis/pdo/sqlite.phpunit.xml | 2 +- 7 files changed, 102 insertions(+), 7 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') 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', ), ), ), diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index eb650fa1e..69eece24f 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -10,7 +10,7 @@ stopOnIncomplete="false" stopOnSkipped="false"> - + diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index 351f690d5..e68c3e028 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -10,7 +10,7 @@ stopOnIncomplete="false" stopOnSkipped="false"> - + diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index ae139b7a9..1871f6221 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -10,7 +10,7 @@ stopOnIncomplete="false" stopOnSkipped="false"> - + -- 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/codeigniter/database/DB_driver_test.php | 36 +++++++++++++++++++++++++++ tests/mocks/autoloader.php | 15 +++++++++-- 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 ++++++++++++ 10 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 tests/codeigniter/database/DB_driver_test.php 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') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php new file mode 100644 index 000000000..fb40f0608 --- /dev/null +++ b/tests/codeigniter/database/DB_driver_test.php @@ -0,0 +1,36 @@ +$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/mocks/autoloader.php b/tests/mocks/autoloader.php index dd5929206..22448139e 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -53,13 +53,24 @@ function autoload($class) $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('CI_DB', 'DB', $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 @@ function autoload($class) { return FALSE; } - + var_dump($file); throw new InvalidArgumentException("Unable to load $class."); } 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') 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') 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/codeigniter/database/query_builder/.gitkeep | 0 tests/mocks/autoloader.php | 4 ++-- 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 6 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 tests/codeigniter/database/query_builder/.gitkeep delete mode 100644 tests/mocks/database/schema/.gitkeep (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 22448139e..f1bdb5d6f 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -62,7 +62,7 @@ function autoload($class) elseif (strpos($class, 'CI_DB') === 0) { $dir = BASEPATH.'database'.DIRECTORY_SEPARATOR; - $file = $dir.str_replace('CI_DB', 'DB', $subclass).'.php'; + $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php'; } else { @@ -82,7 +82,7 @@ function autoload($class) { return FALSE; } - var_dump($file); + throw new InvalidArgumentException("Unable to load $class."); } 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 --- .../database/query_builder/get_test.php | 48 ++++++++++++++++ tests/mocks/database/db/querybuilder.php | 10 ++++ tests/mocks/database/schema/skeleton.php | 65 ++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/get_test.php create mode 100644 tests/mocks/database/db/querybuilder.php create mode 100644 tests/mocks/database/schema/skeleton.php (limited to 'tests') 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 000000000..6f98ded4f --- /dev/null +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -0,0 +1,48 @@ +set_dsn(DB_DRIVER), TRUE); + + $this->ci_instance_var('db', $db); + + $loader = new Mock_Core_Loader(); + $loader->dbforge(); + + $forge = $this->ci_instance->dbforge; + + Mock_Database_Schema_Skeleton::create_tables($forge); + Mock_Database_Schema_Skeleton::create_data($db); + + $this->query_builder = $db; + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_get_simple() + { + $jobs = $this->query_builder->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']); + } + +} \ 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 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') 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') 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') 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') 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 333ce0db32865d1e6d6a96207e5c9306bd40c676 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 02:34:06 +0700 Subject: Fixed schema --- tests/codeigniter/database/query_builder/get_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index 6f98ded4f..e6fe319c5 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -20,7 +20,7 @@ class Get_test extends CI_TestCase { $forge = $this->ci_instance->dbforge; - Mock_Database_Schema_Skeleton::create_tables($forge); + Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER); Mock_Database_Schema_Skeleton::create_data($db); $this->query_builder = $db; -- 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 --- .../database/query_builder/get_test.php | 31 +++++++----- .../database/query_builder/select_test.php | 37 +++++++++++++++ tests/mocks/database/schema/skeleton.php | 55 +++++++++++++++++++--- 3 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 tests/codeigniter/database/query_builder/select_test.php (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index e6fe319c5..dd946a40c 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -9,19 +9,10 @@ class Get_test extends CI_TestCase { public function set_up() { - $config = Mock_Database_DB::config(DB_DRIVER); - $connection = new Mock_Database_DB($config); - $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); + $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); - $this->ci_instance_var('db', $db); - - $loader = new Mock_Core_Loader(); - $loader->dbforge(); - - $forge = $this->ci_instance->dbforge; - - Mock_Database_Schema_Skeleton::create_tables($forge, DB_DRIVER); - Mock_Database_Schema_Skeleton::create_data($db); + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); $this->query_builder = $db; } @@ -44,5 +35,21 @@ class Get_test extends CI_TestCase { $this->assertEquals('Accountant', $jobs[2]['name']); $this->assertEquals('Musician', $jobs[3]['name']); } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_get_where() + { + $job1 = $this->query_builder->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/select_test.php b/tests/codeigniter/database/query_builder/select_test.php new file mode 100644 index 000000000..ba2f21b64 --- /dev/null +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -0,0 +1,37 @@ +query_builder = $db; + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_select_only_one_collumn() + { + $jobs_name = $this->query_builder->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])); + } + +} \ No newline at end of file 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 From fdc0ea8802c48a5f74df97c013f683d4b264218a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 19:08:00 +0700 Subject: Min, Max, Avg and Sum --- .../database/query_builder/select_test.php | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index ba2f21b64..50a062c9f 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -33,5 +33,65 @@ class Select_test extends CI_TestCase { $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->query_builder->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->query_builder->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->query_builder->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->query_builder->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 -- cgit v1.2.3-24-g4f1b From 0793b1c918a0146920b1a03323f055521c4a9c66 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 5 Apr 2012 21:47:53 +0700 Subject: Rename to db, for more familiar naming convention --- .../database/query_builder/get_test.php | 10 +++--- .../database/query_builder/select_test.php | 36 ++++++++++------------ 2 files changed, 21 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/get_test.php b/tests/codeigniter/database/query_builder/get_test.php index dd946a40c..0751c9332 100644 --- a/tests/codeigniter/database/query_builder/get_test.php +++ b/tests/codeigniter/database/query_builder/get_test.php @@ -5,16 +5,14 @@ class Get_test extends CI_TestCase { /** * @var object Database/Query Builder holder */ - protected $query_builder; + protected $db; public function set_up() { - $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->query_builder = $db; } // ------------------------------------------------------------------------ @@ -24,7 +22,7 @@ class Get_test extends CI_TestCase { */ public function test_get_simple() { - $jobs = $this->query_builder->get('job')->result_array(); + $jobs = $this->db->get('job')->result_array(); // Dummy jobs contain 4 rows $this->assertCount(4, $jobs); @@ -43,7 +41,7 @@ class Get_test extends CI_TestCase { */ public function test_get_where() { - $job1 = $this->query_builder->get('job', array('id' => 1))->result_array(); + $job1 = $this->db->get('job', array('id' => 1))->result_array(); // Dummy jobs contain 1 rows $this->assertCount(1, $job1); diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index 50a062c9f..dbf432a7c 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -5,16 +5,14 @@ class Select_test extends CI_TestCase { /** * @var object Database/Query Builder holder */ - protected $query_builder; + protected $db; public function set_up() { - $db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); Mock_Database_Schema_Skeleton::create_data(); - - $this->query_builder = $db; } // ------------------------------------------------------------------------ @@ -24,9 +22,9 @@ class Select_test extends CI_TestCase { */ public function test_select_only_one_collumn() { - $jobs_name = $this->query_builder->select('name') - ->get('job') - ->result_array(); + $jobs_name = $this->db->select('name') + ->get('job') + ->result_array(); // Check rows item $this->assertArrayHasKey('name',$jobs_name[0]); @@ -41,9 +39,9 @@ class Select_test extends CI_TestCase { */ public function test_select_min() { - $job_min = $this->query_builder->select_min('id') - ->get('job') - ->result_array(); + $job_min = $this->db->select_min('id') + ->get('job') + ->result_array(); // Minimum id was 1 $this->assertEquals('1', $job_min[0]['id']); @@ -56,9 +54,9 @@ class Select_test extends CI_TestCase { */ public function test_select_max() { - $job_max = $this->query_builder->select_max('id') - ->get('job') - ->result_array(); + $job_max = $this->db->select_max('id') + ->get('job') + ->result_array(); // Maximum id was 4 $this->assertEquals('4', $job_max[0]['id']); @@ -71,9 +69,9 @@ class Select_test extends CI_TestCase { */ public function test_select_avg() { - $job_avg = $this->query_builder->select_avg('id') - ->get('job') - ->result_array(); + $job_avg = $this->db->select_avg('id') + ->get('job') + ->result_array(); // Average should be 2.5 $this->assertEquals('2.5', $job_avg[0]['id']); @@ -86,9 +84,9 @@ class Select_test extends CI_TestCase { */ public function test_select_sum() { - $job_sum = $this->query_builder->select_sum('id') - ->get('job') - ->result_array(); + $job_sum = $this->db->select_sum('id') + ->get('job') + ->result_array(); // Sum of ids should be 10 $this->assertEquals('10', $job_sum[0]['id']); -- cgit v1.2.3-24-g4f1b From c0df5a231a28c6038f0a8ab702e090ce0e12b5a5 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 17:35:12 +0700 Subject: Include insert test --- .../database/query_builder/insert_test.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/insert_test.php (limited to 'tests') 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 000000000..5607e8ce1 --- /dev/null +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -0,0 +1,47 @@ +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_insert() + { + $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!'); + + // Do normal insert + $this->assertTrue($this->db->insert('job', $job_data)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_insert_batch() + { + $job_datas = array( + array('name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('name' => 'Cab Driver', 'description' => 'Iam yellow'), + ); + + // Do insert batch + $this->assertTrue($this->db->insert_batch('job', $job_datas)); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 81b6b5d4ea2e63159c443bae19880a78f6ac2f9f Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 17:58:22 +0700 Subject: Insert test --- tests/codeigniter/database/query_builder/insert_test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 5607e8ce1..80073b9ba 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -12,7 +12,6 @@ class Insert_test extends CI_TestCase { $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); - Mock_Database_Schema_Skeleton::create_data(); } // ------------------------------------------------------------------------ @@ -22,7 +21,7 @@ class Insert_test extends CI_TestCase { */ public function test_insert() { - $job_data = array('name' => 'Grocery Sales', 'description' => 'Discount!'); + $job_data = array('id' => 1, 'name' => 'Grocery Sales', 'description' => 'Discount!'); // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); @@ -36,8 +35,8 @@ class Insert_test extends CI_TestCase { public function test_insert_batch() { $job_datas = array( - array('name' => 'Commedian', 'description' => 'Theres something in your teeth'), - array('name' => 'Cab Driver', 'description' => 'Iam yellow'), + array('id' => 2, 'name' => 'Commedian', 'description' => 'Theres something in your teeth'), + array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); // Do insert batch -- cgit v1.2.3-24-g4f1b From fc92fc2e4f262a3607898ca7cd8b361d95f09136 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 6 Apr 2012 18:00:55 +0700 Subject: Add truncate --- tests/codeigniter/database/query_builder/insert_test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 80073b9ba..78587d2e9 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -4,6 +4,7 @@ class Insert_test extends CI_TestCase { /** * @var object Database/Query Builder holder + * @see ./mocks/schema/skeleton.php */ protected $db; @@ -12,6 +13,9 @@ class Insert_test extends CI_TestCase { $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); Mock_Database_Schema_Skeleton::create_tables(); + + // Truncate the current datas + $this->db->truncate('job'); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 80c0e3df5998a2a4b2376a6361f4690b783446df Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 01:15:53 +0700 Subject: Check the insert result --- tests/codeigniter/database/query_builder/insert_test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 78587d2e9..5dfccce82 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -29,6 +29,12 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); + + $job_1 = $this->db->get('job')->row(); + + // Check the result + $this->assertEquals('Grocery Sales', $job_1->name); + } // ------------------------------------------------------------------------ @@ -45,6 +51,11 @@ class Insert_test extends CI_TestCase { // Do insert batch $this->assertTrue($this->db->insert_batch('job', $job_datas)); + + $job_2 = $this->db->get_where('job', array('id' => 2))->row(); + + // Check the result + $this->assertEquals('Commedian', $job_2->name); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d489747059db6a91d5532f35437a812a81f2b98b Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 03:16:25 +0700 Subject: Remove batch test from sqlite --- .../database/query_builder/insert_test.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 5dfccce82..b86feeb74 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -30,10 +30,11 @@ class Insert_test extends CI_TestCase { // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); - $job_1 = $this->db->get('job')->row(); + $jobs = $this->db->get('job')->result_array(); + $job1 = $jobs[0]; // Check the result - $this->assertEquals('Grocery Sales', $job_1->name); + $this->assertEquals('Grocery Sales', $job1['name']); } @@ -49,13 +50,18 @@ class Insert_test extends CI_TestCase { array('id' => 3, 'name' => 'Cab Driver', 'description' => 'Iam yellow'), ); - // Do insert batch - $this->assertTrue($this->db->insert_batch('job', $job_datas)); + // Do insert batch except for sqlite driver + if (strpos(DB_DRIVER, 'sqlite') === FALSE) + { + $this->assertTrue($this->db->insert('job', $job_datas[0])); - $job_2 = $this->db->get_where('job', array('id' => 2))->row(); + $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); + // Check the result + $this->assertEquals('Commedian', $job_2->name); + $this->assertEquals('Cab Driver', $job_3->name); + } } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5ce26c912f11fb859e661a43a6667fba5a5a3ca2 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 7 Apr 2012 03:19:35 +0700 Subject: Typo --- tests/codeigniter/database/query_builder/insert_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index b86feeb74..53ce23c19 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -53,7 +53,7 @@ class Insert_test extends CI_TestCase { // Do insert batch except for sqlite driver if (strpos(DB_DRIVER, 'sqlite') === FALSE) { - $this->assertTrue($this->db->insert('job', $job_datas[0])); + $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(); -- cgit v1.2.3-24-g4f1b