diff options
author | Taufan Aditya <toopay@taufanaditya.com> | 2012-03-28 22:00:56 +0200 |
---|---|---|
committer | Taufan Aditya <toopay@taufanaditya.com> | 2012-03-28 22:00:56 +0200 |
commit | 655a89f4059ebae017d1c4ec5f26aeb2cf4a3bae (patch) | |
tree | fe33f2f905631133d4d9807ef0f75d8d14618392 /tests | |
parent | 3b2587e1559d2cbe751d04f801f999ef3fa4e74c (diff) |
Preliminary Database Test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Bootstrap.php | 3 | ||||
-rw-r--r-- | tests/codeigniter/database/.gitkeep | 0 | ||||
-rw-r--r-- | tests/codeigniter/database/DB_test.php | 44 | ||||
-rw-r--r-- | tests/mocks/database/.gitkeep | 0 | ||||
-rw-r--r-- | tests/mocks/database/db.php | 43 | ||||
-rw-r--r-- | tests/phpunit.xml | 5 |
6 files changed, 91 insertions, 4 deletions
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 --- a/tests/codeigniter/database/.gitkeep +++ /dev/null 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 @@ +<?php + +class DB_test extends CI_TestCase { + + public $db_config; + + public function set_up() + { + $this->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 --- a/tests/mocks/database/.gitkeep +++ /dev/null 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 @@ +<?php + +class Mock_Database_DB { + + private $config = array(); + + /** + * Prepare database configuration skeleton + * + * @param array DB configuration to set + * @return void + */ + public function __construct($config = array()) + { + include_once(BASEPATH.'database/DB.php'); + + $this->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 @@ <directory suffix="test.php">codeigniter/core</directory> <directory suffix="test.php">codeigniter/helpers</directory> <directory suffix="test.php">codeigniter/libraries</directory> - <!-- We'll worry about these later ... - <directory suffix="test.php">codeigniter/libraries</directory> - <directory suffix="test.php">codeigniter/helpers</directory> - --> + <directory suffix="test.php">codeigniter/database</directory> </testsuite> </testsuites> <filters> |