示例#1
0
 /**
  * @group Match
  * @group createnewmatch
  */
 public function testCreateNewMatch()
 {
     $teams = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->get();
     $this->assertNotNull($teams);
     $teams = $teams->toArray();
     $homeIndex = array_rand($teams);
     $teamHome = $teams[$homeIndex];
     unset($teams[$homeIndex]);
     $teamAway = $teams[array_rand($teams)];
     $this->assertNotNull($teamHome);
     $this->assertNotNull($teamAway);
     $matchO = \App\Lib\DsManager\Models\Orm\Match::create(['home_team_id' => $teamHome['id'], 'away_team_id' => $teamAway['id']]);
     $this->assertNotNull($matchO);
     $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first();
     $this->assertNotNull($matchNew);
     $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray());
     $this->assertNotNull($match);
 }
示例#2
0
    return Responder::getJsonResponse(Coach::all(), $response);
});
$api->get('/teams', function ($request, $response, $args) {
    return Responder::getJsonResponse(Team::all(), $response);
});
$api->get('/teams/{id}', function ($request, $response, $args) {
    return Responder::getJsonResponse(Team::complete()->where(['id' => $args['id']])->get(), $response);
});
$api->get('/teams/{id}/players', function ($request, $response, $args) {
    return Responder::getJsonResponse(Team::with('roster')->where(['id' => $args['id']])->get(), $response);
});
$api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) {
    return Responder::getJsonResponse(Player::statistics()->where(['id' => $args['playerId'], 'team_id' => $args['id']])->get(), $response);
});
$api->get('/teams/{id}/coach', function ($request, $response, $args) {
    return Responder::getJsonResponse(Team::with('coach')->where(['id' => $args['id']])->get(), $response);
});
$api->get('/leagues', function ($request, $response, $args) {
    return Responder::getJsonResponse(League::all(), $response);
});
$api->get('/leagues/{id}', function ($request, $response, $args) {
    return Responder::getJsonResponse(League::with('rounds')->where(['id' => $args['id']])->first(), $response);
});
$api->get('/leagues/{id}/rounds/{roundId}', function ($request, $response, $args) {
    return Responder::getJsonResponse(LeagueRound::complete()->where(['id' => $args['roundId']])->first(), $response);
});
$api->put('/leagues/{id}/rounds/{roundId}/simulate', function ($request, $response, $args) {
    return Responder::getJsonResponse(MatchSimulator::simulateRound($args['roundId']), $response);
});
$api->get('/matches', function ($request, $response, $args) {
    return Responder::getJsonResponse(Match::teams()->get(), $response);
示例#3
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']);
     }
 }