public function testCreateTestInvalidActual() { $newTest = new Test(); $newTest->setName("Ping 1234")->setExpectation("toPing"); $this->logIn("ROLE_SUPER_ADMIN"); $this->makeJsonRequest('POST', '/api/tests/group/' . TestGroupFixtures::$groups['group-2']->getId(), ["name" => $newTest->getName(), "expectation" => $newTest->getExpectation()]); $this->assertEquals(Response::HTTP_UNPROCESSABLE_ENTITY, $this->client->getResponse()->getStatusCode()); $this->assertContains("An actual value to test against must be provided.", $this->getResponseContent(TRUE)); $this->assertNull($this->em->getRepository("Overwatch\\TestBundle\\Entity\\Test")->findOneBy(["name" => $newTest->getName()])); }
public function load(ObjectManager $em) { $test1 = new Test(); $test1->setName("Group 1, Test 1")->setActual("8.8.8.8")->setExpectation("toPing")->setGroup($this->getReference("group-1")); $em->persist($test1); $test2 = new Test(); $test2->setName("Group 1, Test 2")->setActual("8.8.8.9")->setExpectation("toPing")->setGroup($this->getReference("group-1")); $em->persist($test2); $test3 = new Test(); $test3->setName("Group 2, Test 3")->setActual("www.google.co.uk")->setExpectation("toPing")->setGroup($this->getReference("group-2")); $em->persist($test3); $this->addReference('test-1', $test1); $this->addReference('test-2', $test2); $this->addReference('test-3', $test3); $em->flush(); }
/** * 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); }
private function createTest($name) { $test = new Test(); $test->setName($name)->setActual("8.8.8.8")->setExpectation("toPing"); return $test; }