Example #1
0
 public function testSetUserSetsUserId()
 {
     $user1 = $this->prophesize('AppBundle\\Entity\\User');
     $user2 = $this->prophesize('AppBundle\\Entity\\User');
     $user1->getId()->willReturn(1);
     $user2->getId()->willReturn(2);
     $this->game->setUser1($user1->reveal());
     $this->game->setUser2($user2->reveal());
     $this->assertEquals($user1->reveal(), $this->game->getUser1());
     $this->assertEquals($user2->reveal(), $this->game->getUser2());
     $this->assertEquals(1, $this->game->getUserId1());
     $this->assertEquals(2, $this->game->getUserId2());
     $this->game->setUser1($user2->reveal());
     $this->game->setUser2($user1->reveal());
     $this->assertEquals($user2->reveal(), $this->game->getUser1());
     $this->assertEquals($user1->reveal(), $this->game->getUser2());
     $this->assertEquals(2, $this->game->getUserId1());
     $this->assertEquals(1, $this->game->getUserId2());
 }
 /**
  * @depends testAddEventShotChangedTurnHit
  * @param Game $game
  */
 public function testAddEventShotChangedTurnHitFollowUpSunk(Game $game)
 {
     $client = static::createClient();
     $client->enableProfiler();
     $apiKey = $this->getApiKeyManager()->generateApiKeyForUser($game->getUser2());
     $body = ['type' => Event::TYPE_SHOT, 'value' => $game->getPlayerShips()[2]];
     $client->request('POST', sprintf('/v1/games/%d/events', $game->getId()), [], [], ['CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json', 'HTTP_AUTHORIZATION' => 'Bearer ' . $apiKey], json_encode($body));
     $response = $client->getResponse();
     $jsonResponse = json_decode($response->getContent(), true);
     $this->validateAddEvent($response);
     /** @var DoctrineDataCollector $doctrineDataCollector */
     $doctrineDataCollector = $client->getProfile()->getCollector('db');
     // SELECT user, SELECT game, SELECT event (getAttackerShots), SELECT event (has game started), SELECT event (whoseTurn), START TRANSACTION, INSERT event, COMMIT
     $this->assertEquals(8, $doctrineDataCollector->getQueryCount());
     $this->assertEquals(['result' => BattleManager::SHOT_RESULT_SUNK], $jsonResponse, $response);
 }