/** * test grabbing all Player Statistics **/ public function testGetAllValidPlayerStatistics() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("playerStatistic"); // create a new Player Statistic and insert to into mySQL $playerStatistic = new PlayerStatistic(null, $this->profile->getProfileId(), $this->VALID_TWEETCONTENT, $this->VALID_TWEETDATE); $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\\Public_html\\Php\\Classes\\PlayerStatistic", $results); // grab the result from the array and validate it $pdoPlayerStatistic = $results[0]; $this->assertEquals($pdoPlayerStatistic->getSportId(), $this->sport->getSportId()); $this->assertEquals($pdoPlayerStatistic->getGame(), $this->VALID_GAME); $this->assertEquals($pdoPlayerStatistic->getPlayer(), $this->VALID_TWEETDATE); $this->assertEquals($pdoPlayerStatistic->getPlayerStatistic(), $this->VALID_TWEETDATE); $this->assertEquals($pdoPlayerStatistic->getStatistic(), $this->VALID_TWEETDATE); }
$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(); } header("Content-type: application/json"); if ($reply->data === null) { unset($reply->data); } echo json_encode($reply);
/** * 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); }