示例#1
0
 /**
  * @test
  * @dataProvider boolProvider
  */
 public function queryRaw($master)
 {
     $sql = "SELECT * FROM abc WHERE def = ? && ghi = ?";
     $params = [123, 456];
     $connect_fx = $master ? 'getMaster' : 'getReplica';
     $connection = $this->_getDisabledMock(ConnectionService::class, [$connect_fx]);
     $adapter = new PdoAdapter($connection);
     $results = $this->_mock_results;
     $db = new PPDO();
     $db->mock($sql, $results);
     $connection->expects($this->once())->method($connect_fx)->will($this->returnValue($db));
     $statement = $master ? $adapter->queryMaster($sql, $params) : $adapter->query($sql, $params);
     // NOTE: fetchAll is being run against raw PDOStatement object, not Adapter wrapper fetchAll method
     $this->assertSame($results, $statement->fetchAll(\PDO::FETCH_ASSOC));
 }
示例#2
0
文件: NQMTest.php 项目: cocur/nqm
 /**
  * @test
  *
  * @covers Cocur\NQM\NQM::execute()
  */
 public function convertParametersShouldNotAddColonIfItIsThere()
 {
     $this->pdo->mock('SELECT * FROM table WHERE key = :key;', [[':key' => 'foo']]);
     $this->queryLoader->shouldReceive('getQuery')->with('foo')->once()->andReturn('SELECT * FROM table WHERE key = :key;');
     $stmt = $this->nqm->execute('foo', [':key' => 'foo']);
     $this->assertInstanceOf('\\PDOStatement', $stmt);
     $this->assertEquals([':key' => 'foo'], $stmt->fetch(\PDO::FETCH_ASSOC));
 }
 /**
  * @param string $sql
  * @param array  $params
  * @param mixed  $results
  * @param bool   $master
  *
  * @return mock
  */
 private function _setupFetch($sql, array $params, $results, $master)
 {
     $connection = $this->_getDisabledMock(ConnectionService::class);
     $target = $this->_getAbstractMock(AdapterAbstract::class, ['query', 'queryMaster'], [$connection]);
     $adapter = new PPDO();
     $adapter->mock($sql, $results);
     $statement = $adapter->prepare($sql);
     $statement->execute($params);
     $target->expects($this->once())->method('query')->with($sql, $params, $master)->will($this->returnValue($statement));
     return $target;
 }