コード例 #1
0
 public function testPlayerShipsAndOtherShips()
 {
     $user1 = $this->prophesize('AppBundle\\Entity\\User');
     $user2 = $this->prophesize('AppBundle\\Entity\\User');
     $user1Ships = ['A1'];
     $user2Ships = ['B2'];
     $user1->getId()->willReturn(1);
     $user2->getId()->willReturn(2);
     $this->game->setUser1Ships($user1Ships);
     $this->game->setUser2Ships($user2Ships);
     $this->game->setUser1($user1->reveal());
     $this->game->setUser2($user2->reveal());
     $this->game->setLoggedUser($user1->reveal());
     $this->assertEquals($user1Ships, $this->game->getPlayerShips());
     $this->assertEquals($user2Ships, $this->game->getOtherShips());
     $this->game->setLoggedUser($user2->reveal());
     $this->assertEquals($user2Ships, $this->game->getPlayerShips());
     $this->assertEquals($user1Ships, $this->game->getOtherShips());
 }
コード例 #2
0
 /**
  * Example request in <strong>Content</strong>:
  *  <pre>{"joinGame":true,"playerShips":["A1","C2","D2","F2","H2","J2","F5","F6","I6","J6","A7","B7","C7","F7","F8","I9","J9","E10","F10","G10"]}</pre>
  *
  * @ApiDoc(
  *  resource=true,
  *  description="Update game",
  *  section="Game",
  *  statusCodes={
  *     204="Game updated",
  *     400="Incorrect parameter provided",
  *     403="No access to game",
  *     404="Game not found",
  *  }
  * )
  *
  * @Tag(expression="'game-' ~ game.getId()")
  * @Tag(expression="'game-' ~ game.getId() ~ 'events'"))
  * @Tag("games")
  * @Security("request.request.get('joinGame') ? game.canJoin(user) : game.belongsToUser(user)")
  * @RequestParam(name="joinGame", requirements=@Assert\EqualTo("true"), allowBlank=true, nullable=true)
  * @RequestParam(name="playerShips", requirements="[A-J]([1-9]|10)", allowBlank=true, map=true)
  *
  * @param ParamFetcher $paramFetcher
  * @param Game $game
  */
 public function patchGameAction(ParamFetcher $paramFetcher, Game $game)
 {
     if ($paramFetcher->get('joinGame')) {
         $game->setUser2($this->getUser());
         $this->createEvent($game, Event::TYPE_JOIN_GAME);
     }
     $playerShips = $paramFetcher->get('playerShips');
     if ($playerShips) {
         $game->setPlayerShips($playerShips);
         $this->createEvent($game, Event::TYPE_START_GAME);
     }
     $this->entityManager->persist($game);
     $this->entityManager->flush();
 }