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/Bootstrap.php | 3 +++ tests/codeigniter/database/.gitkeep | 0 tests/codeigniter/database/DB_test.php | 44 ++++++++++++++++++++++++++++++++++ tests/mocks/database/.gitkeep | 0 tests/mocks/database/db.php | 43 +++++++++++++++++++++++++++++++++ tests/phpunit.xml | 5 +--- 6 files changed, 91 insertions(+), 4 deletions(-) delete mode 100644 tests/codeigniter/database/.gitkeep create mode 100644 tests/codeigniter/database/DB_test.php delete mode 100644 tests/mocks/database/.gitkeep create mode 100644 tests/mocks/database/db.php (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 9f89d1be8..e1649804f 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -6,6 +6,9 @@ error_reporting(E_ALL | E_STRICT); $dir = realpath(dirname(__FILE__)); +// Environment constants +define('ENVIRONMENT', 'testing'); + // Path constants define('PROJECT_BASE', realpath($dir.'/../').'/'); define('BASEPATH', PROJECT_BASE.'system/'); diff --git a/tests/codeigniter/database/.gitkeep b/tests/codeigniter/database/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php new file mode 100644 index 000000000..c1930f5f2 --- /dev/null +++ b/tests/codeigniter/database/DB_test.php @@ -0,0 +1,44 @@ +db_config = new Mock_Database_DB(array( + 'mysql' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + '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(), + ), + )); + } + + // ------------------------------------------------------------------------ + + public function test_db_valid() + { + $db = DB($this->db_config->set_config('mysql'), TRUE); + + $this->assertTrue($db instanceof CI_DB); + $this->assertTrue($db instanceof CI_DB_Driver); + $this->assertTrue($db instanceof CI_DB_active_record); + $this->assertTrue($db instanceof CI_DB_mysql_driver); + } + +} \ No newline at end of file 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 diff --git a/tests/phpunit.xml b/tests/phpunit.xml index dfeecd19f..ffd2a1f0f 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -15,10 +15,7 @@ codeigniter/core codeigniter/helpers codeigniter/libraries - + codeigniter/database -- cgit v1.2.3-24-g4f1b