/** * @group Helpers * @group FixtureGenerator * @group generatefixture */ public function testFixtureGenerator() { $teams = \App\Lib\DsManager\Models\Orm\Team::all(); $rounds = \App\Lib\DsManager\Helpers\LeagueFixtureGenerator::generate($teams->toArray()); //Number of rounds $this->assertCount($teams->count() - 1, $rounds); //Matches for each round foreach ($rounds as $round) { $this->assertCount($teams->count() / 2, $round); } }
function run() { $teamNumber = 16; $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); for ($i = 1; $i <= $teamNumber; $i++) { $team = $rndFiller->getTeam($rndFiller->getLocale()); $teamArray = $team->toArray(); $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); foreach ($teamArray['roster'] as $player) { $player['team_id'] = $teamO->id; \App\Lib\DsManager\Models\Orm\Player::create($player); } $teamArray['coach']['team_id'] = $teamO->id; \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); } }
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]); } } } }
/** * @group Stats */ public function testGetStats() { $match = \App\Lib\DsManager\Models\Orm\Match::where(['simulated' => false])->whereNotNull('league_round_id')->get()->random(1); $this->assertNotEmpty($match); $result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateRound($match->league_round_id); $this->assertNotEmpty($result); $players = \App\Lib\DsManager\Models\Orm\Player::getBest(); $this->assertNotEmpty($players); $teams = \App\Lib\DsManager\Models\Orm\Team::getBest(); $this->assertNotEmpty($teams); }
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);
/** * @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']); } }