/** * @test * @expectedException \Llvdl\Domino\Domain\Exception\InvalidMoveException */ public function cannotAddMoveToUnstartedGame() { $this->assertFalse($this->game->getState()->isStarted()); $player = $this->game->getPlayerByPlayerNumber(1); $play = new Play(1, new Stone(6, 6), Table::SIDE_LEFT); $this->game->addMove($player, $play); }
/** * @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(); }
public function testPersistNewGameState() { // create and persist game with state "ready" $game0 = new Game('test game'); $this->assertTrue($game0->getState()->isEqual(new State(State::READY))); $this->gameRepository->persistGame($game0); // create and persist game with state "ready" $game1 = new Game('test game'); $this->assertTrue($game1->getState()->isEqual(new State(State::READY))); $this->gameRepository->persistGame($game1); $this->clearEntityManager(); // change state to "started" and persist $game2 = $this->gameRepository->findById($game1->getId()); $game2->deal(); $this->assertTrue($game2->getState()->isEqual(new State(State::STARTED))); $this->gameRepository->persistGame($game2); // assert that the state is "started" when reloading the game $game3 = $this->gameRepository->findById($game1->getId()); $this->assertTrue($game3->getState()->isEqual(new State(State::STARTED))); // assert that unchanged game still has state "ready" when reloading the game $game4 = $this->gameRepository->findById($game0->getId()); $this->assertTrue($game4->getState()->isEqual(new State(State::READY))); }