Ejemplo n.º 1
0
 public function testCreate()
 {
     $teamA = new Team();
     $teamA->setPlayerA(new Player(1, 'John Doe'));
     $teamA->setPlayerB(new Player(2, 'James Doe'));
     $teamB = new Team();
     $teamB->setPlayerA(new Player(3, 'John Smith'));
     $teamB->setPlayerB(new Player(4, 'James Smith'));
     $setScore = new SetScore();
     $setScore->setScoresByString('21-18');
     $match = new Match();
     $match->setTeamA($teamA);
     $match->setTeamB($teamB);
     $match->addSetScore($setScore);
     $match->addSetScoreByString('21-16');
     $match->setGameTimeLengthInSeconds(5);
     $validator = Validation::createValidatorBuilder()->addMethodMapping('loadValidatorMetadata')->getValidator();
     $this->assertEmpty($validator->validate($match));
     $this->assertTrue($match->getTeamA() instanceof Team);
     $this->assertTrue($match->getTeamB() instanceof Team);
     $this->assertSame(2, count($match->getSetScores()));
     $this->assertTrue($match->getSetscores()[0] instanceof SetSCore);
     $this->assertTrue($match->getSetscore(1) instanceof SetSCore);
     $this->assertSame(null, $match->getSetScore(3));
     $this->assertSame(5, $match->getGameTimeLengthInSeconds());
     $this->assertSame('[(1) John Doe, (2) James Doe] def [(3) John Smith, (4) James Smith]', $match->__toString());
 }
Ejemplo n.º 2
0
 private function setupMatch()
 {
     $player1 = new Player(1, 'John Doe');
     $player2 = new Player(2, 'James Doe');
     $player3 = new Player(3, 'John Smith');
     $player4 = new Player(4, 'James Smith');
     $teamA = new Team();
     $teamA->setPlayerA($player1);
     $teamA->setPlayerB($player2);
     $teamB = new Team();
     $teamB->setPlayerA($player3);
     $teamB->setPlayerB($player4);
     $match = new Match();
     $match->setTeamA($teamA);
     $match->setTeamB($teamB);
     $match->addSetScore(new SetScore('21-18'));
     $match->addSetScore(new SetScore('16-21'));
     $match->addSetScore(new SetScore('15-8'));
     $match->setGameTimeLengthInSeconds(60);
     $this->entityManager->persist($player1);
     $this->entityManager->persist($player2);
     $this->entityManager->persist($player3);
     $this->entityManager->persist($player4);
     $this->entityManager->persist($teamA);
     $this->entityManager->persist($teamB);
     $this->matchRepository->create($match);
     $this->entityManager->flush();
     return $match;
 }
Ejemplo n.º 3
0
 /**
  * @param string $xmlContent
  * @return Match[]
  */
 public static function getMatches($xmlContent)
 {
     $regex = '/
         \\<br\\>Match\\s\\d+:
         [^?]+
         \\?ID=(?<team1PlayerAID>\\d+)"\\>(?<team1PlayerAName>[^<]+)\\<\\/a\\>
         [^?]+
         \\?ID=(?<team1PlayerBID>\\d+)"\\>(?<team1PlayerBName>[^<]+)\\<\\/a\\>
         [^?]+
         \\?ID=(?<team2PlayerAID>\\d+)"\\>(?<team2PlayerAName>[^<]+)\\<\\/a\\>
         [^?]+
         \\?ID=(?<team2PlayerBID>\\d+)"\\>(?<team2PlayerBName>[^<]+)\\<\\/a\\>
         [^?]+
         \\)
         (?:
             (?:
                 \\sby\\s(?<forfeit>Forfeit)
             )
             |
             (?:
                 \\s(?<score1>\\d+-\\d+)
                 ,\\s(?<score2>\\d+-\\d+)
                 (,\\s(?<score3>\\d+-\\d+))?
                 \\s\\((?<time>\\d+:\\d+)\\)
             )
         )
     /xm';
     preg_match_all($regex, $xmlContent, $regexMatches, PREG_SET_ORDER);
     $matches = [];
     foreach ($regexMatches as $regexMatch) {
         $teamA = new Team();
         $teamA->setPlayerA(new Player($regexMatch['team1PlayerAID'], $regexMatch['team1PlayerAName']));
         $teamA->setPlayerB(new Player($regexMatch['team1PlayerBID'], $regexMatch['team1PlayerBName']));
         $teamB = new Team();
         $teamB->setPlayerA(new Player($regexMatch['team2PlayerAID'], $regexMatch['team2PlayerAName']));
         $teamB->setPlayerB(new Player($regexMatch['team2PlayerBID'], $regexMatch['team2PlayerBName']));
         $match = new Match();
         $match->setTeamA($teamA);
         $match->setTeamB($teamB);
         if ($regexMatch['forfeit'] === 'Forfeit') {
             $setScore1 = new SetScore();
             $setScore1->setTeamBForfeit();
             $match->addSetScore($setScore1);
         } else {
             $match->addSetScoreByString($regexMatch['score1']);
             $match->addSetScoreByString($regexMatch['score2']);
             $score3 = $regexMatch['score3'];
             if ($score3 !== '') {
                 $match->addSetScoreByString($score3);
             }
         }
         $matches[] = $match;
     }
     return $matches;
 }
Ejemplo n.º 4
0
 public function testCreate()
 {
     $team = new Team();
     $team->setPlayerA(new Player(1, 'John Doe'));
     $team->setPlayerB(new Player(2, 'James Doe'));
     $validator = Validation::createValidatorBuilder()->addMethodMapping('loadValidatorMetadata')->getValidator();
     $this->assertEmpty($validator->validate($team));
     $this->assertTrue($team->getPlayerA() instanceof Player);
     $this->assertTrue($team->getPlayerB() instanceof Player);
     $this->assertSame('[(1) John Doe, (2) James Doe]', $team->__toString());
 }
Ejemplo n.º 5
0
 /**
  * @param Team $team
  * @return Team
  */
 private function createTeamIfNotFound($team)
 {
     $team->setPlayerA($this->createPlayerIfNotFound($team->getPlayerA()));
     $team->setPlayerB($this->createPlayerIfNotFound($team->getPlayerB()));
     try {
         return $this->teamRepository->findOneByPlayers($team->getPlayerA(), $team->getPlayerB());
     } catch (EntityNotFoundException $e) {
         $this->teamRepository->persist($team);
         return $team;
     }
 }
Ejemplo n.º 6
0
 protected function getDummyMatch()
 {
     $teamA = new Team();
     $teamA->setPlayerA(new Player(1, 'John Doe'));
     $teamA->setPlayerB(new Player(2, 'James Doe'));
     $teamB = new Team();
     $teamB->setPlayerA(new Player(3, 'John Smith'));
     $teamB->setPlayerB(new Player(4, 'James Smith'));
     $setScore = new SetScore();
     $setScore->setScoresByString('21-18');
     $match = new Match();
     $match->setTeamA($teamA);
     $match->setTeamB($teamB);
     $match->addSetScore($setScore);
     return $match;
 }