Exemplo n.º 1
0
 /**
  * @return array
  */
 private function prepareAValidGameInDatabase()
 {
     $this->createPlayers(['Player_A', 'Player_B', 'Player_C', 'Player_D']);
     $em = $this->getEntityManager();
     $playerA = $em->getRepository('AppBundle:Player')->findOneById(1);
     $playerB = $em->getRepository('AppBundle:Player')->findOneById(2);
     $playerC = $em->getRepository('AppBundle:Player')->findOneById(3);
     $playerD = $em->getRepository('AppBundle:Player')->findOneById(4);
     $teamA = new Team();
     $teamA->setPlayerA($playerA);
     $teamA->setPlayerB($playerB);
     $teamB = new Team();
     $teamB->setPlayerA($playerC);
     $teamB->setPlayerB($playerD);
     $round = new Round();
     $round->setDate(\DateTime::createFromFormat('Y-m-d', '1980-04-30'));
     $this->getEntityManager()->persist($teamA);
     $this->getEntityManager()->persist($teamB);
     $this->getEntityManager()->persist($round);
     $this->getEntityManager()->flush($teamA);
     $this->getEntityManager()->flush($teamB);
     $this->getEntityManager()->flush($round);
     return [$round, $teamA, $teamB];
 }
Exemplo n.º 2
0
 /**
  * Creates all possible team combination with the new player
  *
  * @param EntityManager $em
  * @param Player $newPlayer
  */
 private function createTeamsForNewPlayer(EntityManager $em, Player $newPlayer)
 {
     $players = $em->getRepository('AppBundle:Player')->findAll();
     foreach ($players as $existingPlayer) {
         if ($existingPlayer->getId() === $newPlayer->getId()) {
             continue;
         }
         $team = new Team();
         $team->setPlayerA($existingPlayer);
         $team->setPlayerB($newPlayer);
         $em->persist($team);
     }
     $em->flush();
 }
Exemplo n.º 3
0
 /**
  * @param Player $playerA
  * @param Player $playerB
  */
 protected function createTeam(Player $playerA, Player $playerB)
 {
     $team = new Team();
     $team->setPlayerA($playerA);
     $team->setPlayerB($playerB);
     $this->getEntityManager()->persist($team);
     $this->getEntityManager()->flush();
 }