if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) { throw new InvalidArgumentException("id can not be empty or negative", 405); } //sanitize and trim other fields $playerStatisticGameId = filter_input(INPUT_GET, "gameId", FILTER_SANITIZE_NUMBER_INT); $playerStatisticPlayerId = filter_input(INPUT_GET, "playerId", FILTER_SANITIZE_NUMBER_INT); $playerStatisticStatisticId = filter_input(INPUT_GET, "statisticId", FILTER_SANITIZE_NUMBER_INT); $playerStatisticValue = filter_input(INPUT_GET, "statisticValue", FILTER_SANITIZE_NUMBER_INT); //handle REST calls, while only allowing administrators to access database-modifying methods if ($method === "GET") { //set XSRF cookie setXsrfCookie("/"); //get the playerStatistic based on the given field } if (empty($playerStatisticGameId) === false) { $playerStatistic = PlayerStatistic::getPlayerStatisticByPlayerStatisticGameId($pdo, $playerStatisticGameId); $reply->data = $playerStatistic; } else { if (empty($playerStatisticPlayerId) === false) { $playerStatistics = PlayerStatistic::getPlayerStatisticByPlayerStatisticPlayerId($pdo, $playerStatisticPlayerId)->toArray(); $reply->data = $playerStatistics; } else { if (empty($playerStatisticStatisticId) === false) { $playerStatistic = PlayerStatistic::getPlayerStatisticByPlayerStatisticStatisticId($pdo, $playerStatisticStatisticId); $reply->data = $playerStatistic; } } } } catch (Exception $exception) { $reply->status = $exception->getCode(); $reply->message = $exception->getMessage();
/** * test inserting a valid PlayerStatistic and verify that the actual mySQL data matches **/ public function testInsertValidPlayerStatisticByPlayerStatisticGameId() { // 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 $pdoPlayerStatistic = PlayerStatistic::getPlayerStatisticByPlayerStatisticGameId($this->getPDO(), $this->game->getGameId(), $this->player->getPlayerId(), $this->team->getTeamId(), $this->statistic->getStatisticId()); $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("playerStatistic")); $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); }