/** * 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 creating a Team and then deleting it **/ public function testDeleteValidTeam() { // 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()); // delete the Team from mySQL $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("team")); $team->delete($this->getPDO()); // grab the data from mySQL and enforce the Team does not exist $pdoTeam = Team::getTeamByTeamId($this->getPDO(), $team->getTeamId()); $this->assertNull($pdoTeam); $this->assertEquals($numRows, $this->getConnection()->getRowCount("team")); }