Example #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);
 }
 function run()
 {
     $leagues = ['friendly' => 16, 'europa league' => 8];
     $teams = Team::all()->toArray();
     foreach ($leagues as $league => $teamsNum) {
         $teamCopy = $teams;
         $league = League::create(['name' => $league, 'teams' => $teamsNum]);
         //Create Rounds
         shuffle($teamCopy);
         $teamCopy = array_splice($teamCopy, 0, $teamsNum);
         $rounds = LeagueFixtureGenerator::generate($teamCopy);
         foreach ($rounds as $i => $round) {
             $leagueRound = LeagueRound::create(['league_id' => $league->id, 'day' => $i + 1]);
             foreach ($round as $match) {
                 $newMatch = Match::create(['home_team_id' => $match['home_team_id'], 'away_team_id' => $match['away_team_id'], 'league_round_id' => $leagueRound->id]);
             }
         }
     }
 }
Example #3
0
$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);
});
$api->post('/matches', function ($request, $response, $args) {
    $json = $request->getBody();
    $json = json_decode($json, true);
    return Responder::getJsonResponse(Match::create($json), $response);
});
$api->get('/matches/{id}', function ($request, $response, $args) {
    return Responder::getJsonResponse(Match::complete()->where(['id' => $args['id']])->first(), $response);
});
$api->get('/matches/{id}/result', function ($request, $response, $args) {
    $result = MatchResult::complete()->where(['id' => $args['id']])->first();
    return Responder::getJsonResponse($result, $response);
});
$api->put('/matches/{id}/simulate', function ($request, $response, $args) {
    return Responder::getJsonResponse(MatchSimulator::simulateCompleteResult($args['id']), $response);
});
$api->run();