/** * Generates the pairings for * a given tournament. * * @param int $tournamentID * @param Carbon $begin * @param Carbon $finish * * @throws Illuminate\Database\Eloquent\ModelNotFoundException * * @return array */ public function pairings($tournamentID, \Carbon\Carbon $begin = null, \Carbon\Carbon $finish = null) { $rankedPlayers = $this->playersService->getRankedPlayers($tournamentID); $pairings = \Pairings::ranked($rankedPlayers, $tournamentID); $matches = $this->registerMatches($pairings, $tournamentID, $begin, $finish); return $matches; }
/** * Tests if the pairings method generates * a bye match when an odd number of * players is provided. */ public function testServicePairingsWithByeRegistered() { $tournamentID = 1; $numberOfPlayers = 11; $numberOfMatches = intval(floor($numberOfPlayers / 2) + $numberOfPlayers % 2); $fakeStaticMatch = m::mock('App\\Models\\Match'); $fakePairings = getFakePairings($numberOfMatches, true); $this->fakePlayersService->shouldReceive('getRankedPlayers')->andReturn([]); \Pairings::shouldReceive('ranked')->withArgs([[], $tournamentID])->once()->andReturn($fakePairings); $this->fakeMatchesService->shouldReceive('addMatch')->times($numberOfMatches)->andReturn($fakeStaticMatch); $this->service->pairings($tournamentID); }