throw new InvalidArgumentException("id can not be empty or negative", 405); } //sanitize and trim other fields $teamId = filter_input(INPUT_GET, "teamId", FILTER_VALIDATE_INT); $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");
/** * test grabbing a Team by team city **/ public function testGetValidTeamByTeamCity() { // 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::getTeamByTeamCity($this->getPDO(), $team->getTeamCity()); $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); }