public function testGetSchedulesForWeek()
 {
     // No DB connection required if we're using fixtures
     $mapper = new \IBL\ScheduleMapper();
     $rawSchedules = unserialize(file_get_contents('./fixtures/raw-schedules-27.txt'));
     $franchiseMap = unserialize(file_get_contents('./fixtures/franchise-mappings.txt'));
     $testSchedules = $mapper->generate($rawSchedules, $franchiseMap);
     $this->assertEquals(24, count($testSchedules), "Found correct number of schedules for a week");
     $this->assertEquals(true, array_key_exists('MAD', $testSchedules), "Found MAD in week 27 schedule");
 }
 public function testMainPage()
 {
     $dbConn = new \PDO('pgsql:host=localhost;dbname=ibl_stats', 'stats', 'st@ts=Fun');
     // Load data that we will need for the front page
     $gameMapper = new \IBL\GameMapper($dbConn);
     $franchiseMapper = new \IBL\FranchiseMapper($dbConn);
     $rotationMapper = new \IBL\RotationMapper($dbConn);
     $scheduleMapper = new \IBL\ScheduleMapper($dbConn);
     $games = unserialize(file_get_contents('./fixtures/games.txt'));
     $franchises = unserialize(file_get_contents('./fixtures/franchises.txt'));
     $standings = new \IBL\Standings($games, $franchises);
     $regularStandings = $standings->generateRegular();
     $currentWeek = 27;
     $currentGames = unserialize(file_get_contents('./fixtures/games-27.txt'));
     $currentResults = $gameMapper->generateResults($currentGames, $franchises);
     $rotations = unserialize(file_get_contents('./fixtures/rotations-27.txt'));
     $currentRotations = $rotationMapper->generateRotations($rotations, $franchises);
     $rawSchedules = unserialize(file_get_contents('./fixtures/raw-schedules-27.txt'));
     $franchiseMap = unserialize(file_get_contents('./fixtures/franchise-mappings.txt'));
     $currentSchedules = $scheduleMapper->generate($rawSchedules, $franchiseMap);
     // Display the data
     $response = $this->_twig->render('index.html', array('currentWeek' => $currentWeek, 'currentResults' => $currentResults, 'currentRotations' => $currentRotations, 'currentSchedules' => $currentSchedules, 'franchises' => $franchises, 'rotationWeek' => $currentWeek, 'scheduleWeek' => $currentWeek, 'standings' => $regularStandings));
     $standingsHeader = "Standings through week 27";
     $resultsHeader = "Results for week 27";
     $rotationsHeader = "Rotations for Week 27";
     $scheduleHeader = "Schedule for Week 27";
     $rotation = "KC Greinke, CHN Lilly -2, CHN Wells -2";
     $this->assertTrue(stripos($response, $standingsHeader) !== false);
     $this->assertTrue(stripos($response, $resultsHeader) !== false);
     $this->assertTrue(stripos($response, $rotationsHeader) !== false);
     $this->assertTrue(stripos($response, $scheduleHeader) !== false);
     // Look for a known team abbreviation
     $this->assertTrue(stripos($response, "MAD") !== false);
     // Look for a specific rotation to appear
     $this->assertTrue(stripos($response, $rotation) !== false);
 }
$franchises = $franchiseMapper->findAll();
$standings = new \IBL\Standings($games, $franchises);
$regularStandings = $standings->generateRegular();
$currentWeek = $gameMapper->getCurrentWeek();
$currentResults = $gameMapper->generateResults($gameMapper->findByWeek($currentWeek), $franchises);
/**
 * If we don't have any rotations for the current week, make sure to grab
 * rotations for the previous week
 */
$rotations = $rotationMapper->findByWeek($currentWeek);
$rotationWeek = $currentWeek;
if (count($rotations) == 0) {
    $rotations = $rotationMapper->findByWeek($currentWeek - 1);
    $rotationWeek = $currentWeek - 1;
}
$currentRotations = $rotationMapper->generateRotations($rotations, $franchises);
/**
 * We need to use some intelligence in deciding what schedules we need to
 * show. If we have less than half the results in, show the schedule
 * from the previous week
 */
if (count($currentResults) < 12) {
    $scheduleWeek = $currentWeek - 1;
} else {
    $scheduleWeek = $currentWeek;
}
$franchiseMap = $franchiseMapper->generateMap($scheduleMapper->teamsTable);
$rawSchedule = $scheduleMapper->findByWeek($scheduleWeek);
$currentSchedules = $scheduleMapper->generate($rawSchedule, $franchiseMap);
// Display the data
echo $twig->render('index.html', array('currentWeek' => $currentWeek, 'currentResults' => $currentResults, 'currentRotations' => $currentRotations, 'currentSchedules' => $currentSchedules, 'franchises' => $franchises, 'rotationWeek' => $rotationWeek, 'scheduleWeek' => $scheduleWeek, 'standings' => $regularStandings));