diff options
Diffstat (limited to 'tests/mocks/database')
-rwxr-xr-x | tests/mocks/database/ci_test.sqlite | bin | 19456 -> 19456 bytes | |||
-rw-r--r-- | tests/mocks/database/config/mysql.php | 10 | ||||
-rw-r--r-- | tests/mocks/database/config/pdo/mysql.php | 18 | ||||
-rw-r--r-- | tests/mocks/database/config/pdo/pgsql.php | 14 | ||||
-rw-r--r-- | tests/mocks/database/config/pdo/sqlite.php | 14 | ||||
-rw-r--r-- | tests/mocks/database/config/pgsql.php | 10 | ||||
-rw-r--r-- | tests/mocks/database/config/sqlite.php | 10 | ||||
-rw-r--r-- | tests/mocks/database/db.php | 26 | ||||
-rw-r--r-- | tests/mocks/database/db/driver.php | 7 | ||||
-rw-r--r-- | tests/mocks/database/db/querybuilder.php | 9 | ||||
-rw-r--r-- | tests/mocks/database/drivers/mysql.php | 9 | ||||
-rw-r--r-- | tests/mocks/database/drivers/pdo.php | 8 | ||||
-rw-r--r-- | tests/mocks/database/drivers/postgre.php | 9 | ||||
-rw-r--r-- | tests/mocks/database/drivers/sqlite.php | 9 | ||||
-rw-r--r-- | tests/mocks/database/schema/skeleton.php | 55 |
15 files changed, 114 insertions, 94 deletions
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite Binary files differindex 23a3de2a4..44dcef9ec 100755 --- a/tests/mocks/database/ci_test.sqlite +++ b/tests/mocks/database/ci_test.sqlite diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php index ace0a31b1..a590b9f53 100644 --- a/tests/mocks/database/config/mysql.php +++ b/tests/mocks/database/config/mysql.php @@ -1,7 +1,7 @@ <?php return array( - + // Typical Database configuration 'mysql' => array( 'dsn' => '', @@ -9,7 +9,7 @@ return array( 'username' => 'travis', 'password' => '', 'database' => 'ci_test', - 'dbdriver' => 'mysql', + 'dbdriver' => 'mysql' ), // Database configuration with failover @@ -28,7 +28,7 @@ return array( 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'mysql', - ), - ), - ), + ) + ) + ) );
\ No newline at end of file diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php index cefb6b008..96608f787 100644 --- a/tests/mocks/database/config/pdo/mysql.php +++ b/tests/mocks/database/config/pdo/mysql.php @@ -1,16 +1,16 @@ <?php return array( - + // Typical Database configuration 'pdo/mysql' => array( - 'dsn' => '', + 'dsn' => 'mysql:host=localhost;dbname=ci_test', 'hostname' => 'localhost', 'username' => 'travis', 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'mysql', + 'subdriver' => 'mysql' ), // Database configuration with failover @@ -21,17 +21,17 @@ return array( 'password' => 'wrong password', 'database' => 'not_ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'mysql', + 'subdriver' => 'mysql', 'failover' => array( array( - 'dsn' => '', + 'dsn' => 'mysql:host=localhost;dbname=ci_test', 'hostname' => 'localhost', 'username' => 'travis', 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'mysql', - ), - ), - ), + 'subdriver' => 'mysql' + ) + ) + ) );
\ No newline at end of file diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php index 5196e9ad9..e55e3ea77 100644 --- a/tests/mocks/database/config/pdo/pgsql.php +++ b/tests/mocks/database/config/pdo/pgsql.php @@ -1,7 +1,7 @@ <?php return array( - + // Typical Database configuration 'pdo/pgsql' => array( 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', @@ -10,7 +10,7 @@ return array( 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'pgsql', + 'subdriver' => 'pgsql' ), // Database configuration with failover @@ -21,7 +21,7 @@ return array( 'password' => 'wrong password', 'database' => 'not_ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'pgsql', + 'subdriver' => 'pgsql', 'failover' => array( array( 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', @@ -30,8 +30,8 @@ return array( 'password' => '', 'database' => 'ci_test', 'dbdriver' => 'pdo', - 'pdodriver' => 'pgsql', - ), - ), - ), + 'subdriver' => 'pgsql' + ) + ) + ) );
\ No newline at end of file diff --git a/tests/mocks/database/config/pdo/sqlite.php b/tests/mocks/database/config/pdo/sqlite.php index c68b4b213..1bf56b3ac 100644 --- a/tests/mocks/database/config/pdo/sqlite.php +++ b/tests/mocks/database/config/pdo/sqlite.php @@ -10,7 +10,7 @@ return array( 'password' => 'sqlite', 'database' => 'sqlite', 'dbdriver' => 'pdo', - 'pdodriver' => 'sqlite', + 'subdriver' => 'sqlite' ), // Database configuration with failover @@ -21,7 +21,7 @@ return array( 'password' => 'sqlite', 'database' => 'sqlite', 'dbdriver' => 'pdo', - 'pdodriver' => 'sqlite', + 'subdriver' => 'sqlite', 'failover' => array( array( 'dsn' => 'sqlite:/'.realpath(__DIR__.'/../..').'/ci_test.sqlite', @@ -29,9 +29,9 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => 'sqlite', - 'dbdriver' => 'pdo', - 'pdodriver' => 'sqlite', - ), - ), - ), + 'dbdriver' => 'pdo', + 'subdriver' => 'sqlite' + ) + ) + ) );
\ No newline at end of file diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php index c06af8ce0..1444b0066 100644 --- a/tests/mocks/database/config/pgsql.php +++ b/tests/mocks/database/config/pgsql.php @@ -1,7 +1,7 @@ <?php return array( - + // Typical Database configuration 'pgsql' => array( 'dsn' => '', @@ -9,7 +9,7 @@ return array( 'username' => 'postgres', 'password' => '', 'database' => 'ci_test', - 'dbdriver' => 'postgre', + 'dbdriver' => 'postgre' ), // Database configuration with failover @@ -28,7 +28,7 @@ return array( '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 index 755ce2a3a..d37ee4871 100644 --- a/tests/mocks/database/config/sqlite.php +++ b/tests/mocks/database/config/sqlite.php @@ -9,7 +9,7 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', - 'dbdriver' => 'sqlite3', + 'dbdriver' => 'sqlite3' ), // Database configuration with failover @@ -27,8 +27,8 @@ return array( 'username' => 'sqlite', 'password' => 'sqlite', 'database' => realpath(__DIR__.'/..').'/ci_test.sqlite', - 'dbdriver' => 'sqlite3', - ), - ), - ), + 'dbdriver' => 'sqlite3' + ) + ) + ) );
\ No newline at end of file diff --git a/tests/mocks/database/db.php b/tests/mocks/database/db.php index 59028ed9c..75658530b 100644 --- a/tests/mocks/database/db.php +++ b/tests/mocks/database/db.php @@ -6,7 +6,7 @@ class Mock_Database_DB { * @var array DB configuration */ private $config = array(); - + /** * Prepare database configuration skeleton * @@ -21,7 +21,7 @@ class Mock_Database_DB { /** * Build DSN connection string for DB driver instantiate process * - * @param string Group name + * @param string Group name * @return string DSN Connection string */ public function set_dsn($group = 'default') @@ -45,9 +45,9 @@ class Mock_Database_DB { ); $config = array_merge($this->config[$group], $params); - $dsnstring = ( ! empty($config['dsn'])) ? $config['dsn'] : FALSE; - $pdodriver = ( ! empty($config['pdodriver'])) ? $config['pdodriver'] : FALSE; - $failover = ( ! empty($config['failover'])) ? $config['failover'] : FALSE; + $dsnstring = empty($config['dsn']) ? FALSE : $config['dsn']; + $subdriver = empty($config['subdriver']) ? FALSE: $config['subdriver']; + $failover = empty($config['failover']) ? FALSE : $config['failover']; $dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password'] .'@'.$config['hostname'].'/'.$config['database']; @@ -55,7 +55,7 @@ class Mock_Database_DB { // Build the parameter $other_params = array_slice($config, 6); if ($dsnstring) $other_params['dsn'] = $dsnstring; - if ($pdodriver) $other_params['pdodriver'] = $pdodriver; + if ($subdriver) $other_params['subdriver'] = $subdriver; if ($failover) $other_params['failover'] = $failover; return $dsn.'?'.http_build_query($other_params); @@ -65,28 +65,27 @@ class Mock_Database_DB { * Return a database config array * * @see ./config - * @param string Driver based configuration - * @return array + * @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 + * @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 + try { $db = DB($group, $query_builder); } @@ -97,4 +96,5 @@ class Mock_Database_DB { return $db; } + }
\ No newline at end of file diff --git a/tests/mocks/database/db/driver.php b/tests/mocks/database/db/driver.php index cb1820277..65ac2c4cc 100644 --- a/tests/mocks/database/db/driver.php +++ b/tests/mocks/database/db/driver.php @@ -1,7 +1,7 @@ <?php class Mock_Database_DB_Driver extends CI_DB_driver { - + /** * @var object The actual Driver */ @@ -16,7 +16,10 @@ class Mock_Database_DB_Driver extends CI_DB_driver { */ public function __construct($driver_class, $config = array()) { - if (is_string($driver_class)) $this->ci_db_driver = new $driver_class($config); + if (is_string($driver_class)) + { + $this->ci_db_driver = new $driver_class($config); + } } /** diff --git a/tests/mocks/database/db/querybuilder.php b/tests/mocks/database/db/querybuilder.php index 1b95c92af..3f2252622 100644 --- a/tests/mocks/database/db/querybuilder.php +++ b/tests/mocks/database/db/querybuilder.php @@ -1,10 +1,3 @@ <?php -if ( ! class_exists('CI_DB_query_builder')) -{ - class Mock_Database_DB_QueryBuilder extends CI_DB_active_record {} -} -else -{ - class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {} -} +class Mock_Database_DB_QueryBuilder extends CI_DB_query_builder {}
\ No newline at end of file diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php index 34a74e2bf..e0c1fb06c 100644 --- a/tests/mocks/database/drivers/mysql.php +++ b/tests/mocks/database/drivers/mysql.php @@ -1,16 +1,17 @@ <?php class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver { - + /** * Instantiate the database driver * - * @param string DB Driver class name - * @param array DB configuration to set - * @return void + * @param string DB Driver class name + * @param array DB configuration to set + * @return void */ public function __construct($config = array()) { parent::__construct('CI_DB_mysql_driver', $config); } + }
\ No newline at end of file diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php index 590e19552..17768eed7 100644 --- a/tests/mocks/database/drivers/pdo.php +++ b/tests/mocks/database/drivers/pdo.php @@ -1,13 +1,13 @@ <?php class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver { - + /** * Instantiate the database driver * - * @param string DB Driver class name - * @param array DB configuration to set - * @return void + * @param string DB Driver class name + * @param array DB configuration to set + * @return void */ public function __construct($config = array()) { diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php index 0df905963..5a45115fa 100644 --- a/tests/mocks/database/drivers/postgre.php +++ b/tests/mocks/database/drivers/postgre.php @@ -1,16 +1,17 @@ <?php class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver { - + /** * Instantiate the database driver * - * @param string DB Driver class name - * @param array DB configuration to set - * @return void + * @param string DB Driver class name + * @param array DB configuration to set + * @return void */ public function __construct($config = array()) { parent::__construct('CI_DB_postgre_driver', $config); } + }
\ No newline at end of file diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php index 76a182cbf..512467520 100644 --- a/tests/mocks/database/drivers/sqlite.php +++ b/tests/mocks/database/drivers/sqlite.php @@ -1,16 +1,17 @@ <?php class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver { - + /** * Instantiate the database driver * - * @param string DB Driver class name - * @param array DB configuration to set - * @return void + * @param string DB Driver class name + * @param array DB configuration to set + * @return void */ public function __construct($config = array()) { parent::__construct('CI_DB_sqlite3_driver', $config); } + }
\ No newline at end of file diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 671336cc4..18e1ddd4d 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -41,8 +41,7 @@ class Mock_Database_Schema_Skeleton { return static::$db; } - - + /** * Create the dummy tables * @@ -54,20 +53,20 @@ class Mock_Database_Schema_Skeleton { static::$forge->add_field(array( 'id' => array( 'type' => 'INTEGER', - 'constraint' => 3, + 'constraint' => 3 ), 'name' => array( 'type' => 'VARCHAR', - 'constraint' => 40, + 'constraint' => 40 ), 'email' => array( 'type' => 'VARCHAR', - 'constraint' => 100, + 'constraint' => 100 ), 'country' => array( 'type' => 'VARCHAR', - 'constraint' => 40, - ), + 'constraint' => 40 + ) )); static::$forge->add_key('id', TRUE); static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); @@ -76,18 +75,35 @@ class Mock_Database_Schema_Skeleton { static::$forge->add_field(array( 'id' => array( 'type' => 'INTEGER', - 'constraint' => 3, + 'constraint' => 3 ), 'name' => array( 'type' => 'VARCHAR', - 'constraint' => 40, + 'constraint' => 40 ), 'description' => array( - 'type' => 'TEXT', - ), + 'type' => 'TEXT' + ) )); static::$forge->add_key('id', TRUE); static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE)); + + // Misc Table + static::$forge->add_field(array( + 'id' => array( + 'type' => 'INTEGER', + 'constraint' => 3 + ), + 'key' => array( + 'type' => 'VARCHAR', + 'constraint' => 40 + ), + 'value' => array( + 'type' => 'TEXT' + ) + )); + static::$forge->add_key('id', TRUE); + static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE)); } /** @@ -103,24 +119,29 @@ class Mock_Database_Schema_Skeleton { array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'), array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'), array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'), - array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'), + array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK') ), 'job' => array( - array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), + array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'), - array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'), - array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'), + array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'), + array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician') ), + 'misc' => array( + array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'), + array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%') + ) ); - foreach ($data as $table => $dummy_data) + foreach ($data as $table => $dummy_data) { static::$db->truncate($table); foreach ($dummy_data as $single_dummy_data) { - static::$db->insert($table, $single_dummy_data); + static::$db->insert($table, $single_dummy_data); } } } + }
\ No newline at end of file |