diff options
author | Taufan Aditya <toopay@taufanaditya.com> | 2012-03-28 22:56:46 +0200 |
---|---|---|
committer | Taufan Aditya <toopay@taufanaditya.com> | 2012-03-28 22:56:46 +0200 |
commit | a8a2e3325c128ccdc941daba3bba10b78bf2d098 (patch) | |
tree | 56f3896e8a2d24482159bcb16c5cacc556c75c90 | |
parent | 655a89f4059ebae017d1c4ec5f26aeb2cf4a3bae (diff) |
Travis setup and minor cleanup
-rw-r--r-- | .travis.yml | 8 | ||||
-rwxr-xr-x | system/database/DB.php | 7 | ||||
-rw-r--r-- | tests/Bootstrap.php | 3 | ||||
-rw-r--r-- | tests/codeigniter/database/DB_test.php | 45 | ||||
-rw-r--r-- | tests/codeigniter/database/query_builder/.gitkeep | 0 | ||||
-rw-r--r-- | tests/mocks/database/db.php | 45 | ||||
-rw-r--r-- | tests/mocks/database/models/.gitkeep | 0 |
7 files changed, 75 insertions, 33 deletions
diff --git a/.travis.yml b/.travis.yml index 29111bcf5..c6a4b5ece 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,18 @@ php: - 5.3 - 5.4 +env: + - DB=mysql + - DB=pgsql + - DB=sqlite + before_script: - pyrus channel-discover pear.php-tools.net - pyrus install http://pear.php-tools.net/get/vfsStream-0.11.2.tgz - phpenv rehash + - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi" + - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi" + - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi" script: phpunit --configuration tests/phpunit.xml diff --git a/system/database/DB.php b/system/database/DB.php index 96e495515..e9434231c 100755 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -138,7 +138,12 @@ function &DB($params = '', $active_record_override = NULL) class CI_DB extends CI_DB_driver { } } - require_once(BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'); + // Load the DB driver + $driver_file = BASEPATH.'database/drivers/'.$params['dbdriver'].'/'.$params['dbdriver'].'_driver.php'; + + if ( ! file_exists($driver_file)) show_error('Invalid DB driver'); + + require_once($driver_file); // Instantiate the DB adapter $driver = 'CI_DB_'.$params['dbdriver'].'_driver'; diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index e1649804f..9f89d1be8 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -6,9 +6,6 @@ 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/DB_test.php b/tests/codeigniter/database/DB_test.php index c1930f5f2..10e8dec64 100644 --- a/tests/codeigniter/database/DB_test.php +++ b/tests/codeigniter/database/DB_test.php @@ -2,11 +2,31 @@ class DB_test extends CI_TestCase { - public $db_config; + // ------------------------------------------------------------------------ - public function set_up() + public function test_db_invalid() { - $this->db_config = new Mock_Database_DB(array( + $db_config = new Mock_Database_DB(array( + 'undefined' => array( + 'dsn' => '', + 'hostname' => 'undefined', + 'username' => 'undefined', + 'password' => 'undefined', + 'database' => 'undefined', + 'dbdriver' => 'undefined', + ), + )); + + $this->setExpectedException('InvalidArgumentException', 'CI Error: Invalid DB driver'); + + Mock_Database_DB::DB($db_config->set_dsn('undefined'), TRUE); + } + + // ------------------------------------------------------------------------ + + public function test_db_valid() + { + $db_config = new Mock_Database_DB(array( 'mysql' => array( 'dsn' => '', 'hostname' => 'localhost', @@ -14,30 +34,13 @@ class DB_test extends CI_TestCase { '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); + $db = Mock_Database_DB::DB($db_config->set_dsn('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); } diff --git a/tests/codeigniter/database/query_builder/.gitkeep b/tests/codeigniter/database/query_builder/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/codeigniter/database/query_builder/.gitkeep 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 --- /dev/null +++ b/tests/mocks/database/models/.gitkeep |