/** * @param $teamsAmount * @param $matcheAmount * * @dataProvider tournamentTeamsProvider */ public function testSuccessLeagueDrawWithDifferrentTeamsAmount($teamsAmount, $matchesAmount) { /** * @var $tournament Tournament */ $tournament = Factory::create('App\\Models\\Tournament'); /** * @var $tournament Tournament */ $league = Factory::create('App\\Models\\League'); Factory::times($teamsAmount)->create('App\\Models\\Team', ['leagueId' => $league->id])->each(function ($team, $key) use($tournament) { $tournament->tournamentTeams()->create(['teamId' => $team->id, 'tournamentId' => $tournament->id]); }); $tournament->status = Tournament::STATUS_STARTED; $tournament->save(); $this->assertTrue($tournament instanceof Tournament); // verify total matches amount $this->assertEquals($matchesAmount, $tournament->matches()->getResults()->count()); /** * @var $matches Collection * @var $team TournamentTeam */ $matches = Match::where(['tournamentId' => $tournament->id])->get(); foreach ($tournament->tournamentTeams()->getResults() as $team) { // verify matches per team $this->assertEquals(($teamsAmount - 1) * 2, $matches->filter(function ($match) use($team) { return $match->homeTournamentTeamId == $team->id || $match->awayTournamentTeamId == $team->id; })->count()); } }
public function update($matchId, MatchUpdate $request) { /** * @var $match Match */ $match = Match::findOrFail($matchId); $match->update($request->get('match')); return $this->response->collection(Match::where(['id' => $matchId])->get(), new MatchTransformer(), 'matches'); }
/** * @param $teams * @param $matches * @param $result * * @dataProvider matchesProvider */ public function testSerializerWithMatchesList($teams, $matches, $result) { /** * @var $tournament Tournament */ $tournament = Factory::create(Tournament::class); $league = Factory::create(League::class); for ($i = 1; $i <= $teams; $i++) { TournamentTeam::forceCreate(['id' => $i, 'tournamentId' => $tournament->id, 'teamId' => array_get(Factory::create(Team::class, ['leagueId' => $league->id]), 'id')]); } foreach ($matches as $key => $match) { Match::create(['tournamentId' => $tournament->id, 'homeTournamentTeamId' => $match['homeTeamId'], 'awayTournamentTeamId' => $match['awayTeamId'], 'homeScore' => $match['homeScore'], 'awayScore' => $match['awayScore'], 'homePenaltyScore' => 0, 'awayPenaltyScore' => 0, 'resultType' => $match['resultType'], 'gameType' => Match::GAME_TYPE_GROUP_STAGE, 'status' => Match::STATUS_FINISHED, 'round' => $key]); } $serializer = new StandingsSerializer(); $collection = $serializer->collection(Match::where(['tournamentId' => $tournament->id])->get()); foreach ($result as $teamScore) { $item = $collection->first(function ($key, $item) use($teamScore) { return $item['teamId'] == $teamScore['team']; }); $this->assertEquals($item['position'], $teamScore['position']); } }
protected function cleanupMatches() { Log::info('Clean up matches'); return Match::where(['tournamentId' => $this->tournament->id])->delete(); }
<?php require __DIR__ . '/../../bootstrap/autoload.php'; $app = (require_once __DIR__ . '/../../bootstrap/app.php'); $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); use App; $response = $kernel->handle($request = Illuminate\Http\Request::capture()); $tournament = App\Models\Tournament::find(1); App\Models\Match::where(['tournamentId' => $tournament->id])->delete(); $event = new App\Events\TournamentWasStarted($tournament); $handler = new App\Listeners\Tournament\DrawLeague(); $handler->handle($event);
/** * Removes a match from the DB. * * @param Administrator $admin * @param int $matchID * * @throws ModelNotFoundException * * @return boolean */ public function removeMatch(Administrator $admin, $matchID) { return Match::where('id', $matchID)->where('created_by', $admin->id)->firstOrFail()->delete(); }