/** * test grabbing a TeamStatistic that does not exist **/ public function testGetInvalidTeamStatistic() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("teamStatistic"); // create a new TeamStatistics and insert to into mySQL $teamStatistic = new TeamStatistic($this->game->getGameId(), $this->team->getTeamId(), $this->statistic->getStatisticId(), $this->VALID_TEAMSTATISTICVALUE); $teamStatistic->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $results = TeamStatistic::getAllTeamStatistics($this->getPDO()); $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("teamStatistic")); $this->assertCount(1, $results); $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Sprots\\TeamStatistic", $results); // grab the result from the array and validate it $pdoTeamStatistic = $results[0]; $this->assertEquals($pdoTeamStatistic->getTeamStatisticGameId(), $this->game->getGameId()); $this->assertEquals($pdoTeamStatistic->getTeamStatisticTeamId(), $this->team->getTeamId()); $this->assertEquals($pdoTeamStatistic->getTeamStatisticStatisticId(), $this->statistic->getStatisticId()); $this->assertEquals($pdoTeamStatistic->getTeamStatisticValue(), $this->VALID_TEAMSTATISTICVALUE); }
public function testGetAllValidStatistic() { //count the numbers of rows and save $numRows = $this->getConnection()->getRowCount("statistic"); //create a new Game and insert into mySQL $statistic = new Statistic(null, $this->VALID_STATISTICNAME); $statistic->insert($this->getPDO()); //grab the data from mySQL and enforce the fields match $results = Statistic::getAllStatistic($this->getPDO()); $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount('statistic')); $this->assertCount(1, $results); $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Sprots\\Statistic", $results); // grab the result from the array and validate it $pdoStatistic = $results[0]; $this->assertEquals($pdoStatistic->getStatisticName(), $this->VALID_STATISTICNAME); }
if ($method === "GET") { //set XSRF cookie setXsrfCookie("/"); if (empty($id) === false) { $statistic = Statistic::getStatisticByStatisticId($pdo, $id); if ($statistic !== null && $statistic->getStatisticId() === $_SESSION["statistic"]->getStatisticId()) { $reply->data = $statistic; } } else { if (empty($name) === false) { $statistic = Statistic::getStatisticByStatisticName($pdo, $statisticName); if ($statistic !== null && $statistic->getStatisticId() === $_SESSION["statistic"]->getStatisticId()) { $reply->data = $statistic; } } } } if ($method === "GET") { setXsrfCookie("/"); $statistics = Statistic::getAllStatistic($pdo)->toArray(); $reply->data = $statistics; } } 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);