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 /tests/mocks/database/db.php | |
parent | 655a89f4059ebae017d1c4ec5f26aeb2cf4a3bae (diff) |
Travis setup and minor cleanup
Diffstat (limited to 'tests/mocks/database/db.php')
-rw-r--r-- | tests/mocks/database/db.php | 45 |
1 files changed, 37 insertions, 8 deletions
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 |