Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
    $teamApiId = filter_input(INPUT_GET, "teamApiId", FILTER_SANITIZE_STRING);
    $teamCity = filter_input(INPUT_GET, "teamCity", FILTER_SANITIZE_STRING);
    $teamName = filter_input(INPUT_GET, "teamName", FILTER_SANITIZE_STRING);
    //get the team based on the given field
    if (empty($id) === false) {
        $team = Team::getTeamByTeamId($pdo, $id);
        $reply->data = $team;
    } elseif (empty($teamId) === false) {
        $team = Team::getTeamByTeamApiId($pdo, $teamApiId);
        $reply->date = $team;
    } elseif (empty($teamCity) === false) {
        $team = Team::getTeamByTeamCity($pdo, $teamCity);
        $reply->date = $team;
    } elseif (empty($teamName) === false) {
        $team = Team::getTeamByTeamName($pdo, $teamName);
        $reply->date = $team;
    } else {
        $reply->data = Team::getAllTeams($pdo)->toArray();
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
} catch (TypeError $typeError) {
    $reply->status = $typeError->getCode();
    $reply->message = $typeError->getMessage();
}
header("Content-type: application/json");
if ($reply->data === null) {
    unset($reply->data);
}
echo json_encode($reply);
Exemplo n.º 3
0
 /**
  * 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);
 }