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);
 }
<?php

include 'bootstrap.php';
// Load data that we will need for the front page
$gameMapper = new \IBL\GameMapper($container['db_connection']);
$franchiseMapper = new \IBL\FranchiseMapper($container['db_connection']);
$rotationMapper = new \IBL\RotationMapper($container['db_connection']);
$scheduleMapper = new \IBL\ScheduleMapper($container['db_connection']);
$games = $gameMapper->findAll();
$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) {
<?php

include 'test_bootstrap.php';
$conn = new PDO('pgsql:host=localhost;dbname=ibl_stats', 'stats', 'st@ts=Fun');
echo "Collecting raw schedules for week 27...\n";
$mapper = new \IBL\ScheduleMapper($conn);
$rawSchedules = $mapper->findByWeek(27);
echo "Writing schedule objects into fixture file...\n";
file_put_contents('./fixtures/raw-schedules-27.txt', serialize($rawSchedules));
echo "Done\n";