/** * Create dependent objects before running each test */ public final function setUp() { //run the default setUp() method first parent::setUp(); //create and insert a Sport to own the test playerStatistic $this->sport = new Sport(null, "sportName", "sportLeague"); $this->sport->insert($this->getPDO()); //create and insert a team to own the test playerStatistic $this->team = new Team(null, $this->sport->getSportId(), $this->VALID_TEAMAPIID, "TeamCity", "TeamName"); $this->team->insert($this->getPDO()); $this->team2 = new Team(null, $this->sport->getSportId(), $this->VALID_TEAMAPIID2, "TeamCity2", "TeamName2"); $this->team2->insert($this->getPDO()); //create and insert a Game to own the test playerStatistic $this->game = new Game(null, $this->team->getTeamId(), $this->team2->getTeamId(), "2015-03-23 15:23:04"); $this->game->insert($this->getPDO()); // calculate the date (same as unit test) $this->VALID_GAMETIME = \DateTime::createFromFormat("Y-m-d H:i:s", "2015-03-23 15:23:04"); $this->VALID_GAMETIME2 = \DateTime::createFromFormat("Y-m-d H:i:s", "2015-03-23 16:23:04"); //create and insert a Player to own the test playerStatistic // int $newPlayerId = null, int $newPlayerApiId, int $newPlayerTeamId, int $newPlayerSportId, string $newPlayerName $this->player = new Player(null, $this->VALID_PLAYERAPIID, $this->team->getTeamId(), $this->sport->getSportId(), "PlayerName"); $this->player->insert($this->getPDO()); $this->player2 = new Player(null, $this->VALID_PLAYERAPIID2, $this->team2->getTeamId(), $this->sport->getSportId(), "PlayerNames"); $this->player2->insert($this->getPDO()); //create and insert a Statistic to own the test playerStatistic $this->statistic = new Statistic(null, "statisticName"); $this->statistic->insert($this->getPDO()); }
/** * test grabbing all players **/ public function testGetAllValidPlayers() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("player"); // create a new player and insert to into mySQL $player = new Player(null, $this->VALID_PLAYERAPIID, $this->team->getTeamId(), $this->sport->getSportId(), $this->VALID_PLAYERNAME); $player->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $results = Player::getAllPlayers($this->getPDO()); $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("player")); $this->assertCount(1, $results); $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Sprots\\Player", $results); // grab the result from the array and validate it $pdoPlayer = $results[0]; $this->assertEquals($pdoPlayer->getPlayerId(), $player->getPlayerId()); $this->assertEquals($pdoPlayer->getPlayerApiId(), $this->VALID_PLAYERAPIID); $this->assertEquals($pdoPlayer->getPlayerTeamId(), $this->team->getTeamId()); $this->assertEquals($pdoPlayer->getPlayerSportId(), $this->sport->getSportId()); $this->assertEquals($pdoPlayer->getPlayerName(), $this->VALID_PLAYERNAME); }
/** * test grabbing all Teams **/ public function testGetAllValidTeams() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("team"); // create a new Team and insert to into mySQL $team = new Team(null, $this->sport->getSportId(), $this->VALID_TEAMAPIID, $this->VALID_TEAMCITY, $this->VALID_TEAMNAME); $team->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $results = Team::getAllTeams($this->getPDO()); $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("team")); $this->assertCount(1, $results); $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Sprots\\Team", $results); // grab the result from the array and validate it $pdoTeam = $results[0]; $this->assertEquals($pdoTeam->getTeamSportId(), $this->sport->getSportId()); $this->assertEquals($pdoTeam->getTeamApiId(), $this->VALID_TEAMAPIID); $this->assertEquals($pdoTeam->getTeamCity(), $this->VALID_TEAMCITY); $this->assertEquals($pdoTeam->getTeamName(), $this->VALID_TEAMNAME); //$this->assertEquals($pdoTeam->getTeamSportId(), $this->VALID_TEAMSPORTID); }
/** * Test grabbing all of Names **/ public function testGetAllValidSportNames() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("sport"); // create a new sport and insert it into the db $sport = new Sport(null, $this->VALID_SPORTLEAGUE, $this->VALID_SPORTNAME); $sport->insert($this->getPDO()); // grab the data from the db and enforce the fields match our expectations $results = Sport::getAllSportNames($this->getPDO()); $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("sport")); $this->assertCount(1, $results); $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Sprots\\Sport", $results); //grab the results from the array and validate it $pdoSport = $results[0]; $this->assertEquals($pdoSport->getSportName(), $this->VALID_SPORTNAME); }