public function testTurns() { $randomPlayer = new DrunkPlayer(); $game = new Game(); $game->addPlayer($randomPlayer, PlayerInterface::SYMBOL_X); $table = $game->getTurn(); // First turn will be only in middle $this->assertEquals(1, $this->countSymbols($table)); $this->assertEquals(PlayerInterface::SYMBOL_X, $table[1][1]); $table = $game->doTurn($this->findEmptySpot($table), PlayerInterface::SYMBOL_O); // we know that our turn definitely will be in corner $this->assertEquals(2, $this->countSymbols($table)); $this->assertEquals(PlayerInterface::SYMBOL_O, $table[0][0]); $table = $game->getTurn(); $this->assertEquals(3, $this->countSymbols($table)); for ($x = 4; $x < 9; $x += 2) { if (!$game->getWinner()) { $table = $game->doTurn($this->findEmptySpot($table), PlayerInterface::SYMBOL_O); $this->assertEquals($x, $this->countSymbols($table)); } if (!$game->getWinner()) { $table = $game->getTurn(); $this->assertEquals($x + 1, $this->countSymbols($table)); } } }
/** * @expectedException \Exception * @expectedExceptionMessage Field is already filled */ public function testDoTurnOnExistingField() { $table = array_fill(0, 3, array_fill(0, 3, null)); $table[1][1] = PlayerInterface::SYMBOL_X; $game = new Game($table); $game->doTurn([1, 1], PlayerInterface::SYMBOL_X); $result = $game->getTable(); $this->assertEquals($table, $result); }