public function test_db_failover() { $config = Mock_Database_DB::config(DB_DRIVER); $connection = new Mock_Database_DB($config); $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER . '_failover'), TRUE); $this->assertTrue($db instanceof CI_DB); $this->assertTrue($db instanceof CI_DB_Driver); }
public function test_db_valid() { $config = Mock_Database_DB::config(DB_DRIVER); $connection = new Mock_Database_DB($config); // E_DEPRECATED notices thrown by mysql_connect(), mysql_pconnect() // on PHP 5.5+ cause the tests to fail if (DB_DRIVER === 'mysql' && version_compare(PHP_VERSION, '5.5', '>=')) { error_reporting(E_ALL & ~E_DEPRECATED); } $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); $this->assertTrue($db instanceof CI_DB); $this->assertTrue($db instanceof CI_DB_Driver); }
/** * Initialize both database and forge components */ public static function init($driver) { if (empty(static::$db) && empty(static::$forge)) { $config = Mock_Database_DB::config($driver); $connection = new Mock_Database_DB($config); $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE); CI_TestCase::instance()->ci_instance_var('db', $db); $loader = new CI_Loader(); $loader->dbforge(); $forge = CI_TestCase::instance()->ci_instance_var('dbforge'); static::$db = $db; static::$forge = $forge; static::$driver = $driver; } return static::$db; }
/** * 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'); } self::$dbdriver = $this->config[$group]['dbdriver']; if (isset($this->config[$group]['subdriver'])) { self::$subdriver = $this->config[$group]['subdriver']; } $params = array('dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => FALSE, 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'stricton' => FALSE); $config = array_merge($this->config[$group], $params); $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']; // Build the parameter $other_params = array_slice($config, 6); if ($dsnstring) { $other_params['dsn'] = $dsnstring; } if ($subdriver) { $other_params['subdriver'] = $subdriver; } if ($failover) { $other_params['failover'] = $failover; } return $dsn . '?' . http_build_query($other_params); }
public function test_initialize() { $config = Mock_Database_DB::config(DB_DRIVER); $driver_name = current(explode('/', DB_DRIVER)); $driver = $this->{$driver_name}($config[DB_DRIVER]); $this->assertTrue($driver->initialize()); }
public function test_initialize() { $config = Mock_Database_DB::config(DB_DRIVER); sscanf(DB_DRIVER, '%[^/]/', $driver_name); $driver = $this->{$driver_name}($config[DB_DRIVER]); $this->assertTrue($driver->initialize()); }
/** * Initialize both database and forge components */ public static function init($driver) { if (empty(self::$db) && empty(self::$forge)) { // E_DEPRECATED notices thrown by mysql_connect(), mysql_pconnect() // on PHP 5.5+ cause the tests to fail if ($driver === 'mysql' && version_compare(PHP_VERSION, '5.5', '>=')) { error_reporting(E_ALL & ~E_DEPRECATED); } $config = Mock_Database_DB::config($driver); $connection = new Mock_Database_DB($config); $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE); CI_TestCase::instance()->ci_instance_var('db', $db); $loader = new CI_Loader(); $loader->dbforge(); $forge = CI_TestCase::instance()->ci_instance_var('dbforge'); self::$db = $db; self::$forge = $forge; self::$driver = $driver; } return self::$db; }