/** * @param Domain\Game $game * * @return Dto\GameDetail */ private function mapGameToGameDetailDto(Domain\Game $game) { $builder = (new Dto\GameDetailBuilder())->id($game->getId())->name($game->getName())->state($game->getState()->getName()); foreach ($game->getPlayers() as $player) { $builder->addPlayer($player->getNumber(), $player->getStones()); } if ($game->getCurrentTurn() !== null) { $builder->turn($game->getCurrentTurn()->getNumber(), $game->getCurrentTurn()->getPlayerNumber()); } return $builder->get(); }
/** * @test * @expectedException \Llvdl\Domino\Domain\Exception\InvalidMoveException */ public function moveOnlyAllowedForCurrentPlayer() { $this->game->deal(); $currentPlayerNumber = $this->game->getCurrentTurn()->getPlayerNumber(); $player = $this->game->getPlayerByPlayerNumber($currentPlayerNumber); $play = new Play(1, new Stone(6, 6), Table::SIDE_LEFT); $nextPlayerNumber = $currentPlayerNumber === 4 ? 1 : $currentPlayerNumber + 1; $nextPlayer = $this->game->getPlayerByPlayerNumber($nextPlayerNumber); $nextPlayer->addStones([new Stone(6, 6)]); $this->game->addMove($nextPlayer, $play); }
public function testPersistCurrentTurn() { $game = new Game('my game'); $game->deal(); $turn = $game->getCurrentTurn(); $this->assertNotNull($turn); $this->gameRepository->persistGame($game); $gameId = $game->getId(); $this->clearEntityManager(); $persistedGame = $this->gameRepository->findById($gameId); $this->assertSameTurn($turn, $persistedGame->getCurrentTurn()); }