/** * @param Request $request * @param FormInterface $form * * @return Response|null */ private function handleCreateGameForm(Request $request, FormInterface $form, CreateGameForm $formObject) { $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $gameId = $this->gameService->createGame($formObject->getName()); return $this->redirectToRoute(self::ROUTE_GAME_DETAIL, ['gameId' => $gameId]); } return; }
public function testCreatedGameHasFourPlayersWithNoStones() { $persistedGame = null; $this->gameRepositoryMock->expects($this->once())->method('persistGame')->with($this->isInstanceOf(Domain\Game::class))->will($this->returnCallback(function (Domain\Game $game) use(&$persistedGame) { // persisting sets the id $this->setPrivateProperty($game, 'id', 42); $persistedGame = $game; return $game; })); $this->gameRepositoryMock->expects($this->any())->method('findById')->with($this->identicalTo(42))->will($this->returnCallback(function () use(&$persistedGame) { return $persistedGame; })); $gameId = $this->gameService->createGame('my game'); $gameDetailDto = $this->gameService->getGameById($gameId); $this->assertNotNull($gameDetailDto); $this->assertInstanceOf(Dto\GameDetail::class, $gameDetailDto); $this->assertCount(4, $gameDetailDto->getPlayers()); foreach ($gameDetailDto->getPlayers() as $player) { $this->assertInstanceOf(Dto\Player::class, $player); $this->assertCount(0, $player->getStones()); } }