public function testEmulatedPrepare() { $resolver = new DalResolver(); Dao::setDalResolver($resolver); $datastore = new MockQlDataStore(); $connection = new MockPdoConnection(); $connection->addConfig('options', [\PDO::ATTR_EMULATE_PREPARES => true]); $connection->config(); $connection->connect(); $connection->setResolver($resolver); $datastore->setConnection($connection); MockQlDao::getDalResolver()->addDataStore('mockql', $datastore); MockQlDao::loadOneWhere(['id' => 'y']); Dao::unsetDalResolver(); }
/** * @param bool $persistent * * @dataProvider switchDBProvider * @throws ConnectionException */ public function testSharedConnection($persistent) { $tmpConn = new MockPdoConnection(); $tmpConn->setResolver(new DalResolver()); $tmpConn->addConfig('options', [\PDO::ATTR_PERSISTENT => $persistent]); $numProcs = count($tmpConn->fetchQueryResults("SHOW FULL PROCESSLIST")); $tmpConn->runQuery("DROP DATABASE IF EXISTS packaged_dal_a"); $tmpConn->runQuery("DROP DATABASE IF EXISTS packaged_dal_b"); $tmpConn->runQuery("CREATE DATABASE packaged_dal_a"); $tmpConn->runQuery("CREATE DATABASE packaged_dal_b"); $tmpConn->runQuery("CREATE TABLE packaged_dal_a.table_a (id int, value varchar(200))"); $tmpConn->runQuery("CREATE TABLE packaged_dal_b.table_b (id int, value varchar(200))"); $tmpConn->runQuery("INSERT INTO packaged_dal_a.table_a VALUES (1, 'test_a')"); $tmpConn->runQuery("INSERT INTO packaged_dal_b.table_b VALUES (1, 'test_b')"); $conn1 = new MockPdoConnection(); $conn1->setResolver(new DalResolver()); $conn1->addConfig('options', [\PDO::ATTR_PERSISTENT => $persistent]); $conn1->addConfig('database', 'packaged_dal_a'); $conn2 = new MockPdoConnection(); $conn2->setResolver(new DalResolver()); $conn2->addConfig('options', [\PDO::ATTR_PERSISTENT => $persistent]); $conn2->addConfig('database', 'packaged_dal_b'); $conn1->connect(); $conn2->connect(); $testSelect = function (MockPdoConnection $conn, $isA) use($tmpConn, $persistent) { $tbl = 'table_' . ($isA ? 'a' : 'b'); $db = 'packaged_dal_' . ($isA ? 'a' : 'b'); $this->assertEquals([['id' => 1, 'value' => $isA ? 'test_a' : 'test_b']], $conn->fetchQueryResults("SELECT * FROM " . $tbl)); if ($persistent) { $this->assertEquals([['db' => $db]], $tmpConn->fetchQueryResults('SELECT DATABASE() AS db')); } }; $testSelect($conn1, true); $testSelect($conn2, false); $testSelect($conn1, true); $testSelect($conn2, false); $this->assertEquals($persistent ? $numProcs : $numProcs + 1, count($tmpConn->fetchQueryResults("SHOW FULL PROCESSLIST"))); $tmpConn->runQuery("DROP DATABASE IF EXISTS packaged_dal_a"); $tmpConn->runQuery("DROP DATABASE IF EXISTS packaged_dal_b"); }