public function testConnect() { // 準備 // MySQLデータベースの作成 $db = new PDO('mysql:', 'root'); $db->exec("CREATE DATABASE IF NOT EXISTS {$this->db_name}"); // 接続・切断 Qb::connect("sqlite:{$this->db_name}.db"); Qb::close(); $this->assertEquals(null, Qb::db()); // オプションチェック Qb::connect("sqlite:{$this->db_name}.db"); $this->assertEquals('id', Qb::config('primary_key')); $this->assertEquals(PDO::ERRMODE_EXCEPTION, Qb::config('error_mode')); $this->assertEquals(JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT, Qb::config('json_options')); Qb::close(); Qb::connect("sqlite:{$this->db_name}.db", ['primary_key' => 'id2', 'error_mode' => PDO::ERRMODE_SILENT, 'json_options' => JSON_HEX_TAG]); $this->assertEquals('id2', Qb::config('primary_key')); $this->assertEquals(PDO::ERRMODE_SILENT, Qb::config('error_mode')); $this->assertEquals(JSON_HEX_TAG, Qb::config('json_options')); Qb::close(); Qb::connect("mysql:dbname={$this->db_name}", 'root', '', ['primary_key' => 'id2', 'error_mode' => PDO::ERRMODE_SILENT, 'json_options' => JSON_HEX_TAG]); $this->assertEquals('id2', Qb::config('primary_key')); $this->assertEquals(PDO::ERRMODE_SILENT, Qb::config('error_mode')); $this->assertEquals(JSON_HEX_TAG, Qb::config('json_options')); Qb::close(); Qb::connect("mysql:dbname={$this->db_name}", 'root', ['primary_key' => 'id2', 'error_mode' => PDO::ERRMODE_SILENT, 'json_options' => JSON_HEX_TAG]); $this->assertEquals('id2', Qb::config('primary_key')); $this->assertEquals(PDO::ERRMODE_SILENT, Qb::config('error_mode')); $this->assertEquals(JSON_HEX_TAG, Qb::config('json_options')); Qb::close(); // 設定テスト Qb::config('c1', 1); $this->assertEquals(1, Qb::config('c1')); }