Ejemplo n.º 1
0
 public function testScorer()
 {
     $league = new League();
     $team1 = new Team();
     $team1->setId(1);
     $league->addTeam($team1);
     $player1 = new Player();
     $player1->setId(1);
     $player1->setTeam($team1);
     $team2 = new Team();
     $team2->setId(2);
     $league->addTeam($team2);
     $player2 = new Player();
     $player2->setId(2);
     $player2->setTeam($team2);
     $fixture = new Fixture();
     $fixture->setTeamHome($team1);
     $fixture->setTeamAway($team2);
     $league->addFixture($fixture);
     $fixture->addEvent(Event::createGoal($fixture, $team1, $player1, 1));
     $fixture->addEvent(Event::createGoal($fixture, $team1, $player1, 2));
     $fixture->addEvent(Event::createGoal($fixture, $team2, $player2, 3));
     $scorer = $this->leagueService->getScorer(array($fixture));
     $this->assertEquals($player1, $scorer[0]->getPlayer());
     $this->assertEquals($player2, $scorer[1]->getPlayer());
     $this->assertEquals(2, $scorer[0]->getGoals());
     $this->assertEquals(1, $scorer[1]->getGoals());
 }
Ejemplo n.º 2
0
 /**
  * @param Fixture $fixture
  * @param string $type
  * @param Team $team
  * @param Player $player
  * @param int $minute
  *
  * @return Event
  */
 public static function create(Fixture $fixture, $type, Team $team, Player $player, $minute)
 {
     $event = new Event();
     $event->setFixture($fixture);
     $event->setType($type);
     $event->setTeam($team);
     $event->setPlayer($player);
     $event->setMinute($minute);
     return $event;
 }
Ejemplo n.º 3
0
 public function testGetGoalEvents()
 {
     $team1 = new Team();
     $team1->setId(1);
     $team2 = new Team();
     $team2->setId(2);
     $fixture = new Fixture();
     $fixture->setTeamHome($team1);
     $fixture->setTeamAway($team2);
     $fixture->addEvent(Event::createGoal($fixture, $team1, new Player(), 1));
     $fixture->addEvent(Event::createChance($fixture, $team2, new Player(), 2));
     $this->assertCount(1, $fixture->getGoalEvents());
 }
Ejemplo n.º 4
0
 public function testChance()
 {
     $event = Event::createChance(new Fixture(), new Team(), new Player(), 1);
     $this->assertTrue($event->isChance());
 }
 /**
  * @param Fixture $fixture
  *
  * @return Event
  */
 public function createRandomEvent(Fixture $fixture)
 {
     $possibleTeams = array($fixture->getTeamHome(), $fixture->getTeamAway());
     /** @var Team $attackingTeam */
     $attackingTeam = $possibleTeams[mt_rand(0, count($possibleTeams) - 1)];
     $defendingTeam = $attackingTeam->equals($fixture->getTeamHome()) ? $fixture->getTeamAway() : $fixture->getTeamHome();
     $attacker = $attackingTeam->getRandomPlayerFromLineup();
     $defender = $defendingTeam->getRandomPlayerFromLineup();
     $eventType = $attacker->getSkillOffense() * 2 > $defender->getSkillDefense() * 3 ? Event::TYPE_GOAL : Event::TYPE_CHANCE;
     $event = Event::create($fixture, $eventType, $attackingTeam, $attacker, $fixture->getMinutesPlayed());
     return $event;
 }
Ejemplo n.º 6
0
 /**
  * @param Event $event
  *
  * @throws MatchException
  */
 public function addEvent(Event $event)
 {
     $this->events[] = $event;
     if ($event->isGoal()) {
         if (null !== $this->teamHome && $event->getTeam()->equals($this->teamHome)) {
             $this->scoreHome++;
         } elseif (null !== $this->teamAway && $event->getTeam()->equals($this->teamAway)) {
             $this->scoreAway++;
         } else {
             throw new MatchException('team with id ' . $event->getTeam()->getId() . ' is not part of this match');
         }
     }
 }