コード例 #1
0
 public function testSaveUpdatesDatabase()
 {
     $mapper = new \IBL\GameMapper($this->_conn);
     $game = new \IBL\Game();
     $game->setWeek(30);
     $game->setHomeTeamId(25);
     $game->setAwayTeamId(26);
     $game->setHomeScore(1);
     $game->setAwayScore(2);
     $mapper->save($game);
     $game->setAwayScore(1);
     $game->setHomeScore(2);
     $mapper->save($game);
     $game2 = $mapper->findById($game->getId());
     $this->assertEquals(2, $game2->getHomeScore());
     $mapper->delete($game);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 public function testGenerateResults()
 {
     // Load a fixture of results for a specific week
     $data = file_get_contents('./fixtures/games-24.txt');
     $testGames = unserialize($data);
     $data = file_get_contents('./fixtures/franchises.txt');
     $testFranchises = unserialize($data);
     // We don't need to pass in a DB connection if we're not using the DB
     $mapper = new \IBL\GameMapper();
     $testResults = $mapper->generateResults($testGames, $testFranchises);
     $testResult = $testResults['MAD'];
     $expectedResult = array('homeTeam' => 'MAD', 'awayTeam' => 'BOW', 'awayScores' => array(4, 5, 2), 'homeScores' => array(3, 6, 3));
     $this->assertEquals($expectedResult, $testResult);
 }
コード例 #4
0
<?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 all games in our season...\n";
$gameMapper = new \IBL\GameMapper($conn);
$allGames = $gameMapper->findAll();
echo "Writing games objects into fixture file...\n";
file_put_contents('./fixtures/games.txt', serialize($allGames));
echo "Done\n";
<?php

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