/** * test grabbing a PlayerStatistic that does not exist **/ public function testGetInvalidPlayerStatistic() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("playerStatistic"); // create a new PlayerStatistics and insert to into mySQL $playerStatistic = new PlayerStatistic($this->game->getGameId(), $this->player->getPlayerID(), $this->team->getTeamId(), $this->statistic->getStatisticId(), $this->VALID_PLAYERSTATISTICVALUE); $playerStatistic->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $results = PlayerStatistic::getAllPlayerStatistics($this->getPDO()); $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("playerStatistic")); $this->assertCount(1, $results); $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Sprots\\PlayerStatistic", $results); // grab the result from the array and validate it $pdoPlayerStatistic = $results[0]; $this->assertEquals($pdoPlayerStatistic->getPlayerStatisticGameId(), $this->game->getGameId()); $this->assertEquals($pdoPlayerStatistic->getPlayerStatisticPlayerId(), $this->player->getPlayerId()); $this->assertEquals($pdoPlayerStatistic->getPlayerStatisticTeamId(), $this->team->getTeamId()); $this->assertEquals($pdoPlayerStatistic->getPlayerStatisticStatisticId(), $this->statistic->getStatisticId()); $this->assertEquals($pdoPlayerStatistic->getPlayerStatisticValue(), $this->VALID_PLAYERSTATISTICVALUE); }
/** * 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); }
$playerTeamId = filter_input(INPUT_GET, "playerTeamId", FILTER_VALIDATE_INT); $playerSportId = filter_input(INPUT_GET, "playerSportId", FILTER_VALIDATE_INT); $playerName = filter_input(INPUT_GET, "playerName", FILTER_SANITIZE_STRING); //get the player based on the given field if (empty($id) === false) { $player = Player::getPlayerByPlayerId($pdo, $id); $reply->data = $player; } elseif (empty($teamId) === false) { $player = Player::getPlayerByPlayerTeamId($pdo, $playerTeamId); $reply->date = $player; } elseif (empty($sportId) === false) { $player = Player::getPlayerByPlayerSportId($pdo, $playerSportId); $reply->date = $player; } elseif (empty($playerName) === false) { $player = Player::getPlayerByPlayerName($pdo, $playerName); $reply->date = $player; } else { $reply->data = Player::getAllPlayers($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);