コード例 #1
0
ファイル: MatchTest.php プロジェクト: pdt256/vbscraper
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Exceeded maximum set scores.
  */
 public function testAddSetScoreThrowsException()
 {
     $match = new Match();
     $match->addSetScore(new SetScore());
     $match->addSetScore(new SetScore());
     $match->addSetScore(new SetScore());
     $match->addSetScore(new SetScore());
 }
コード例 #2
0
 private function getInvalidMatch()
 {
     $setScore = new SetScore();
     $setScore->setTeamAScore(-1);
     $setScore->setTeamBScore(-1);
     $match = new Match();
     $match->addSetScore($setScore);
     return $match;
 }
コード例 #3
0
ファイル: BvbInfoScraper.php プロジェクト: pdt256/vbscraper
 /**
  * @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;
 }
コード例 #4
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;
 }
コード例 #5
0
 private function verifyMatch(Match $match, Player $teamAPlayerA, Player $teamAPlayerB, Player $teamBPlayerA, Player $teamBPlayerB, $score1, $score2, $score3)
 {
     $this->assertEquals((string) $teamAPlayerA, (string) $match->getTeamA()->getPlayerA());
     $this->assertEquals((string) $teamAPlayerB, (string) $match->getTeamA()->getPlayerB());
     $this->assertEquals((string) $teamBPlayerA, (string) $match->getTeamB()->getPlayerA());
     $this->assertEquals((string) $teamBPlayerB, (string) $match->getTeamB()->getPlayerB());
     $this->assertSame($score1, (string) $match->getSetScore(1));
     $this->assertSame($score2, (string) $match->getSetScore(2));
     $this->assertSame($score3, (string) $match->getSetScore(3));
 }
コード例 #6
0
ファイル: DoctrineTestCase.php プロジェクト: pdt256/vbscraper
 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;
 }