本文整理汇总了PHP中PDO::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP PDO::expects方法的具体用法?PHP PDO::expects怎么用?PHP PDO::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDO
的用法示例。
在下文中一共展示了PDO::expects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: it_should_get_a_game
/**
* @test
*/
public function it_should_get_a_game()
{
$game = Game::create();
$identifier = $game->id();
$stmt = $this->getMockBuilder('stdClass')->setMethods(['execute', 'rowCount', 'fetchColumn'])->getMock();
$this->pdo->expects($this->once())->method('prepare')->with($this->equalTo('SELECT data FROM games WHERE id = :id'))->willReturn($stmt);
$stmt->expects($this->once())->method('execute')->with($this->equalTo([':id' => (string) $identifier]));
// $stmt->expects($this->once())
// ->method('rowCount')
// ->willReturn(1);
$stmt->expects($this->once())->method('fetchColumn')->willReturn(json_encode($game->toArray()));
$result = $this->repository->get($identifier);
$this->assertInstanceOf(Game::class, $result);
$this->assertEquals($game->toArray(), $result->toArray());
}
示例2: testUnlockNoLock
public function testUnlockNoLock()
{
$this->mutex->expects($this->never())->method('getConnection')->will($this->returnValue($this->pdo));
$this->pdo->expects($this->never())->method('prepare');
// The stm should not be executed
$this->stmtReleaseLock->expects($this->never())->method('execute');
$result = $this->mutex->unlock();
$this->assertEquals(false, $result);
}
示例3: testFailedAttemptThenSucceeds
public function testFailedAttemptThenSucceeds()
{
$this->factory->expects($this->any())->method('create')->will($this->returnValue($this->pdo));
$pdoStatement = $this->getMock(\PDOStatement::class);
$pdoStatement->expects($this->any())->method('execute')->will($this->onConsecutiveCalls($this->throwException(new \PDOException()), $this->returnValue(true)));
$this->pdo->expects($this->any())->method('prepare')->will($this->returnValue($pdoStatement));
$this->config->expects($this->any())->method('getMaximumAttempts')->will($this->returnValue(2));
$this->assertSame($this->pdo, $this->factory->__invoke($this->config));
}
示例4: setupDbMultiCall
public function setupDbMultiCall($calls)
{
$stmt = $this->getMock(\PDOStatement::class);
$stmt->expects($this->any())->method('execute')->will($this->returnValue(true));
foreach ($calls as $call) {
$stmt->expects($this->any())->method($call['method'])->will($this->returnValue($call['response']));
}
$this->pdo->expects($this->any())->method('prepare')->will($this->returnValue($stmt));
return $stmt;
}