public function testGenerateRotations()
 {
     // We don't pass in the DB connection if we're using fixtures
     $mapper = new \IBL\RotationMapper();
     $data = file_get_contents('./fixtures/rotations-24.txt');
     $testRotations = unserialize($data);
     $data = file_get_contents('./fixtures/franchises.txt');
     $testFranchises = unserialize($data);
     $response = $mapper->generateRotations($testRotations, $testFranchises);
     $testRotation = $response['MAD'];
     $this->assertEquals(23, count($response));
     $this->assertTrue($testRotation !== null);
 }
 public function testSaveUpdatesDatabase()
 {
     $mapper = new \IBL\RotationMapper($this->_conn);
     $rotation = new \IBL\Rotation();
     $rotation->setWeek(29);
     $rotation->setRotation('Huey, Dewey, Louie');
     $rotation->setFranchiseId(0);
     $mapper->save($rotation);
     $rotation2 = $mapper->findById($rotation->getId());
     $this->assertEquals($rotation->getId(), $rotation2->getId());
     $mapper->delete($rotation);
     $mapper = new \IBL\RotationMapper($this->_conn);
     $rotation = new \IBL\Rotation();
     $rotation->setWeek(30);
     $rotation->setRotation("Curly, Larry, Moe");
     $rotation->setFranchiseId(0);
     $mapper->save($rotation);
     $rotation->setRotation("Shemp, Larry, Moe");
     $mapper->save($rotation);
     $rotation2 = $mapper->findById($rotation->getId());
     $this->assertEquals("Shemp, Larry, Moe", $rotation2->getRotation());
     $mapper->delete($rotation);
 }
 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 rotations for week 27...\n";
$mapper = new \IBL\RotationMapper($conn);
$rotations = $mapper->findByWeek(27);
echo "Writing rotation objects into fixture file...\n";
file_put_contents('./fixtures/rotations-27.txt', serialize($rotations));
echo "Done\n";