/** * @test */ public function itShouldBuildTheCommand() { $command = LeaveGameCommand::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(LeaveGameCommand::NAME, $command->getCommandName()); }
/** * Handles a LeaveGameCommand * * @param LeaveGameCommand $command * @return void */ public function handleLeaveGameCommand(LeaveGameCommand $command) { ContextContainer::setContext($command->getContext()); try { $miniGame = $this->gameManager->load($command->getGameId()); $miniGame->leaveGame($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 itShouldFailLeavingGame() { $command = LeaveGameCommand::create($this->gameId, $this->playerId, $this->context); $this->givenGameExists(); $this->givenPlayerCanNotLeaveGame(); $this->assertErrorWillBeHandled(); $this->assertGameStateWontChange(); $this->miniGameCommandHandler->handleLeaveGameCommand($command); }