public function testValidateWhenEventNotCreatedYet()
 {
     $constraint = $this->prophesize('AppBundle\\Validator\\Constraints\\UniqueEvent');
     $event = $this->prophesize('AppBundle\\Entity\\Event');
     $game = $this->prophesize('AppBundle\\Entity\\Game');
     $collection = $this->prophesize('Doctrine\\Common\\Collections\\Collection');
     $constraint->uniqueEvents = ['unique event1', 'unique event2'];
     $this->context->getRoot()->willReturn($event);
     $event->getGame()->willReturn($game);
     $game->getPlayerNumber()->willReturn(1);
     $this->eventRepository->findForGameByTypeAndPlayer($game, 'non-unique event', 1)->willReturn($collection);
     $collection->isEmpty()->willReturn(true);
     $this->validator->validate('non-unique event', $constraint->reveal());
 }
 public function testGetShotResultSunk()
 {
     $shotEvent = $this->prophesize('AppBundle\\Entity\\Event');
     $event = $this->prophesize('AppBundle\\Entity\\Event');
     $game = $this->prophesize('AppBundle\\Entity\\Game');
     $shotEvent->getValue()->willReturn('D2');
     $event->getType()->willReturn(Event::TYPE_SHOT);
     $event->getGame()->willReturn($game);
     $event->getValue()->willReturn('C2');
     $event->getPlayer()->willReturn(1);
     $game->getOtherShips()->willReturn(['C2', 'D2']);
     $attackerShots = [$shotEvent];
     $this->eventRepository->findForGameByTypeAndPlayer($game, Event::TYPE_SHOT, 1)->willReturn($attackerShots);
     $this->assertEquals(BattleManager::SHOT_RESULT_SUNK, $this->battleManager->getShotResult($event->reveal()));
 }
 public function testValidatePlayerTurnBecauseFirstShot()
 {
     $constraint = $this->prophesize('AppBundle\\Validator\\Constraints\\IsAllowedToShoot');
     $event = $this->prophesize('AppBundle\\Entity\\Event');
     $game = $this->prophesize('AppBundle\\Entity\\Game');
     $collection = $this->prophesize('Doctrine\\Common\\Collections\\Collection');
     $lastShotEvent = false;
     $event->getType()->willReturn(Event::TYPE_SHOT);
     $event->getGame()->willReturn($game);
     $game->getOtherNumber()->willReturn(2);
     $game->getPlayerNumber()->willReturn(1);
     $collection->isEmpty()->willReturn(false);
     $this->eventRepository->findForGameByTypeAndPlayer($game, Event::TYPE_START_GAME, 2)->willReturn($collection);
     $this->eventRepository->findLastForGameByType($game, Event::TYPE_SHOT)->willReturn($lastShotEvent);
     $this->validator->validate($event->reveal(), $constraint->reveal());
 }