/** * @test */ public function it_should_win_the_game_when_all_ships_have_sunk() { $game = Game::create(1, 2, [2]); $result = $game->fire(Coords::fromArray(['x' => 0, 'y' => 0])); $this->assertFalse($result->isWon()); $result = $game->fire(Coords::fromArray(['x' => 0, 'y' => 1])); $this->assertTrue($result->isWon()); }
/** * @param string $size * @return string */ private function start($size = '') { if (strlen($size) !== 0) { $size = explode(':', $size); $game = Game::create((int) $size[0], (int) $size[1]); } else { $game = Game::create(); echo 'New game started: ' . $game->id() . PHP_EOL; } $this->id = $game->id(); $this->repository()->save($game); echo (string) $game; return 'STARTED ' . $game->id(); }
/** * @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()); }
/** * @test * @expectedException \InvalidArgumentException */ public function it_runs_non_existing_command_run() { $game = Game::create(); $repository = $this->repository($game); $token = 'run'; $service = new ServiceListener($token, $game->id(), $repository); $service->run(); }