/**
  * @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());
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 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));
 }
Exemplo n.º 4
0
 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;
 }