/** * Runs a test * * @Route("/{id}") * @Method({"POST"}) * @ApiDoc( * requirements={ * {"name"="id", "description"="The ID of the test to run", "dataType"="integer", "requirement"="\d+"} * }, * tags={ * "Super Admin" = "#ff1919", * "Admin" = "#ffff33" * } * ) */ public function runTest(Test $test) { if (!$this->isGranted(TestGroupVoter::EDIT, $test->getGroup())) { throw new AccessDeniedHttpException("You must be an admin in this test's group to run it"); } $result = $this->expectationManager->run($test); $this->_em->persist($result); $this->_em->flush(); return new JsonResponse($result, JsonResponse::HTTP_CREATED); }
/** * Returns the latest results for the given test * * @Route("/test/{id}") * @Method({"GET"}) * @ApiDoc( * filters={ * {"name"="pageSize", "description"="How many results to return per page","type"="Integer","default"=10,"maximum"=100}, * {"name"="page", "description"="The page number to return results from","type"="Integer","default"=1} * }, * requirements={ * {"name"="id", "description"="The ID of the test for which to return results for", "dataType"="integer", "requirement"="\d+"} * }, * tags={ * "Super Admin" = "#ff1919", * "Admin" = "#ffff33", * "User" = "#75ff47" * } * ) */ public function getResultsForTest(Request $request, Test $test) { if (!$this->isGranted(TestGroupVoter::VIEW, $test->getGroup())) { throw new AccessDeniedHttpException("You must be a member of this test's group to see it's results"); } $size = $request->query->get('pageSize', 10); $results = $this->getEntityRepository("OverwatchResultBundle:TestResult")->getResults(["test" => $test], $size >= 100 ? 10 : $size, $request->query->get('page', 1)); return new JsonResponse($results); }