/** * @test */ public function itShouldBuildTheCommand() { $command = JoinGameCommand::create($this->gameId, $this->playerId, $this->playerOptions, $this->context); $this->assertEquals($this->playerId, $command->getPlayerId()); $this->assertEquals($this->gameId, $command->getGameId()); $this->assertEquals($this->playerOptions, $command->getPlayerOptions()); $this->assertEquals($this->context, $command->getContext()); $this->assertEquals(JoinGameCommand::NAME, $command->getCommandName()); }
/** * Handles a JoinGameCommand * * @param JoinGameCommand $command * @return void */ public function handleJoinGameCommand(JoinGameCommand $command) { ContextContainer::setContext($command->getContext()); try { $miniGame = $this->gameManager->load($command->getGameId()); $miniGame->addPlayerToGame($command->getPlayerOptions()); $this->gameManager->save($miniGame); } catch (\Exception $e) { $this->errorHandler->handle(new UnableToAddPlayerEvent($command->getGameId(), $command->getPlayerId(), $e->getMessage()), $command->getContext()); } ContextContainer::reset(); }
/** * @test */ public function itShouldFailJoiningGame() { $command = JoinGameCommand::create($this->gameId, $this->playerId, $this->playerOptions, $this->context); $this->givenGameExists(); $this->givenItCanNotAddAPlayerToGame(); $this->assertErrorWillBeHandled(); $this->assertGameStateWontChange(); $this->miniGameCommandHandler->handleJoinGameCommand($command); }