Пример #1
0
 /**
  * @group Match
  * @group MatchResult
  * @group matchresultoutput
  */
 public function testMatchFromExistingTeams()
 {
     $teamHome = 1;
     $teamAway = 2;
     $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
     $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
     $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray());
     $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray());
     $match = new \App\Lib\DsManager\Models\Match($home, $away);
     $result = $match->simulate()->toArray();
     $this->assertNotEmpty($result);
     $this->assertGreaterThanOrEqual(0, $result['goal_away']);
     $this->assertGreaterThanOrEqual(0, $result['goal_home']);
     if ($result['goal_home'] > 0) {
         $this->assertNotEmpty($result['info']['scorers']['home']);
         foreach ($result['info']['scorers']['home'] as $scorerHome) {
             $this->assertEquals($scorerHome->team_id, $teamHome);
         }
     } else {
         $this->assertEmpty($result['info']['scorers']['home']);
     }
     if ($result['goal_away'] > 0) {
         $this->assertNotEmpty($result['info']['scorers']['away']);
         foreach ($result['info']['scorers']['away'] as $scorerAway) {
             $this->assertEquals($scorerAway->team_id, $teamAway);
         }
     } else {
         $this->assertEmpty($result['info']['scorers']['away']);
     }
     if ($result['goal_home'] == $result['goal_away']) {
         $this->assertTrue($result['info']['is_draw']);
     } else {
         $this->assertFalse($result['info']['is_draw']);
     }
 }
Пример #2
0
 /**
  * @param array $ormMatchArray
  * @return Match
  */
 public static function fromArray($ormMatchArray = [])
 {
     $homeTeam = Team::fromArray($ormMatchArray['home_team']);
     $awayTeam = Team::fromArray($ormMatchArray['away_team']);
     return new Match($homeTeam, $awayTeam);
 }