/** * @test */ public function itShouldBuildTheCommand() { $command = StartGameCommand::create($this->gameId, $this->playerId, $this->context); $this->assertEquals($this->playerId, $command->getPlayerId()); $this->assertEquals($this->gameId, $command->getGameId()); $this->assertEquals($this->context, $command->getContext()); $this->assertEquals(StartGameCommand::NAME, $command->getCommandName()); }
/** * Handles a StartGameCommand * * @param StartGameCommand $command * @return void */ public function handleStartGameCommand(StartGameCommand $command) { ContextContainer::setContext($command->getContext()); try { $miniGame = $this->gameManager->load($command->getGameId()); $miniGame->startGame($command->getPlayerId()); $this->gameManager->save($miniGame); } catch (\Exception $e) { $this->errorHandler->handle(new MiniGameAppErrorEvent($command->getGameId(), $command->getPlayerId(), $e->getMessage()), $command->getContext()); } ContextContainer::reset(); }
/** * @test */ public function itShouldFailStartingGame() { $command = StartGameCommand::create($this->gameId, $this->playerId, $this->context); $this->givenGameExists(); $this->givenItCanNotStartTheGame(); $this->assertErrorWillBeHandled(); $this->assertGameStateWontChange(); $this->miniGameCommandHandler->handleStartGameCommand($command); }