diff options
author | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
---|---|---|
committer | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
commit | d6ce1e936d60487ad8ddd099a040fba7d8f88367 (patch) | |
tree | 31dcdda9a24e2ed12135659a4e38cb4f35b0af31 /tests/mocks/database | |
parent | bcee50ff3247dee71d83bf273e52bc10096cd48c (diff) | |
parent | 9e2d5d130eff40592b49337a8ba4d8c170934de1 (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Conflicts:
system/core/Loader.php
system/database/DB_query_builder.php
system/database/drivers/cubrid/cubrid_driver.php
system/database/drivers/mssql/mssql_driver.php
system/database/drivers/mysql/mysql_driver.php
system/database/drivers/mysqli/mysqli_driver.php
system/database/drivers/oci8/oci8_driver.php
system/database/drivers/odbc/odbc_driver.php
system/database/drivers/pdo/pdo_driver.php
system/database/drivers/postgre/postgre_driver.php
system/database/drivers/sqlite/sqlite_driver.php
user_guide_src/source/changelog.rst
user_guide_src/source/database/query_builder.rst
Diffstat (limited to 'tests/mocks/database')
-rwxr-xr-x | tests/mocks/database/ci_test.sqlite | bin | 0 -> 17408 bytes | |||
-rw-r--r-- | tests/mocks/database/config/mysql.php | 34 | ||||
-rw-r--r-- | tests/mocks/database/config/pgsql.php | 34 | ||||
-rw-r--r-- | tests/mocks/database/config/sqlite.php | 35 | ||||
-rw-r--r-- | tests/mocks/database/db.php | 101 | ||||
-rw-r--r-- | tests/mocks/database/schema/.gitkeep | 0 |
6 files changed, 204 insertions, 0 deletions
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite Binary files differnew file mode 100755 index 000000000..37ce4f870 --- /dev/null +++ b/tests/mocks/database/ci_test.sqlite diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php new file mode 100644 index 000000000..ace0a31b1 --- /dev/null +++ b/tests/mocks/database/config/mysql.php @@ -0,0 +1,34 @@ +<?php + +return array( + + // Typical Database configuration + 'mysql' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + ), + + // Database configuration with failover + 'mysql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'mysql', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'travis', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'mysql', + ), + ), + ), +);
\ No newline at end of file diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php new file mode 100644 index 000000000..c06af8ce0 --- /dev/null +++ b/tests/mocks/database/config/pgsql.php @@ -0,0 +1,34 @@ +<?php + +return array( + + // Typical Database configuration + 'pgsql' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'postgre', + ), + + // Database configuration with failover + 'pgsql_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'not_travis', + 'password' => 'wrong password', + 'database' => 'not_ci_test', + 'dbdriver' => 'postgre', + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'postgres', + 'password' => '', + 'database' => 'ci_test', + 'dbdriver' => 'postgre', + ), + ), + ), +);
\ No newline at end of file diff --git a/tests/mocks/database/config/sqlite.php b/tests/mocks/database/config/sqlite.php new file mode 100644 index 000000000..8665e208d --- /dev/null +++ b/tests/mocks/database/config/sqlite.php @@ -0,0 +1,35 @@ +<?php +$dbdriver = is_php('5.4') ? 'sqlite3' : 'sqlite'; + +return array( + + // Typical Database configuration + 'sqlite' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', + 'dbdriver' => $dbdriver, + ), + + // Database configuration with failover + 'sqlite_failover' => array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => '../not_exists.sqlite', + 'dbdriver' => $dbdriver, + 'failover' => array( + array( + 'dsn' => '', + 'hostname' => 'localhost', + 'username' => 'sqlite', + 'password' => 'sqlite', + 'database' => realpath(__DIR__.'/..').'/ci_testf.sqlite', + 'dbdriver' => $dbdriver, + ), + ), + ), +);
\ No newline at end of file diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php new file mode 100644 index 000000000..43a0d391f --- /dev/null +++ b/tests/mocks/database/db.php @@ -0,0 +1,101 @@ +<?php + +class Mock_Database_DB { + + /** + * @var array DB configuration + */ + private $config = array(); + + /** + * Prepare database configuration skeleton + * + * @param array DB configuration to set + * @return void + */ + public function __construct($config = array()) + { + $this->config = $config; + } + + /** + * Build DSN connection string for DB driver instantiate process + * + * @param string Group name + * @return string DSN Connection string + */ + public function set_dsn($group = 'default') + { + if ( ! isset($this->config[$group])) + { + throw new InvalidArgumentException('Group '.$group.' not exists'); + } + + $params = array( + 'dbprefix' => '', + 'pconnect' => FALSE, + 'db_debug' => FALSE, + 'cache_on' => FALSE, + 'cachedir' => '', + 'char_set' => 'utf8', + 'dbcollat' => 'utf8_general_ci', + 'swap_pre' => '', + 'autoinit' => TRUE, + 'stricton' => FALSE, + ); + + $config = array_merge($this->config[$group], $params); + + if ( ! empty($config['dsn'])) + { + $dsn = $config['dsn']; + } + else + { + $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] + .'@'.$config['hostname'].'/'.$config['database']; + + } + + $other_params = array_slice($config, 6); + + return $dsn.'?'.http_build_query($other_params); + } + + /** + * Return a database config array + * + * @see ./config + * @param string Driver based configuration + * @return array + */ + public static function config($driver) + { + $dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR; + + return include($dir.'config'.DIRECTORY_SEPARATOR.$driver.'.php'); + } + + /** + * Main DB method wrapper + * + * @param string Group or DSN string + * @param bool + * @return object + */ + 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 $db; + } +}
\ No newline at end of file diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/mocks/database/schema/.gitkeep |