public function create($name) { $application = new Application(); $application->setName($name); $application->setAppKey($this->uniqueAppKey()); return $application; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { // Add application for e2e test in frontend $application = new Application(); $application->setAppKey("1Z70LMBXQNH6F9U5T4P3O8WVSEGAIDY2JKCR"); $application->setName("Test"); $this->addReference(sprintf('test_application'), $application); $manager->persist($application); $faker = Factory::create('pl_PL'); for ($i = 0; $i < self::APPLICATIONS_NUMBER; $i++) { $application = new Application(); $application->setAppKey(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); $application->setName($faker->sentence(2)); $this->addReference(sprintf('application-%s', $i), $application); $manager->persist($application); } $manager->flush(); }
/** * @ApiDoc( * description="Edit response", * requirements={ * { * "name"="app_key", * "dataType"="String", * "requirement"="true", * "description"="Unique APP_KEY. For example: NACOFXYLPJGQERVBISKTWUHDZM." * } * }, * parameters={ * {"name"="name", "dataType"="string", "required"=true, "description"="Name of application"}, * {"name"="url", "dataType"="string", "required"=true, "description"="Path to application response"}, * {"name"="value", "dataType"="string", "required"=true, "description"="Value that endpoint should return"}, * {"name"="method", "dataType"="string", "required"=true, "description"="HTTP Methods. Allowed: GET, POST, PUT, DELETE"}, * {"name"="statusCode", "dataType"="string", "required"=true, "description"="HTTP Status Code."} * }) * ) * @param Request $request * @param \JSONMockBundle\Entity\Response $response * @param Application $application * @return mixed|Response * @ParamConverter("response", class="JSONMockBundle\Entity\Response", options={"id" = "id"}) * @ParamConverter("application", class="JSONMockBundle\Entity\Application", options={"mapping":{"app_key" = "appKey"}}) */ public function editResponseAction(Request $request, \JSONMockBundle\Entity\Response $response = null, Application $application = null) { if ($application == null) { return JsonResponse::create(array('status' => 'Error', 'message' => 'APP_KEY not match'), 404); } if ($response == null || !$application->getResponses()->contains($response)) { return JsonResponse::create(array('status' => 'Error', 'message' => 'Response not found'), 404); } $form = $this->get('form.factory')->create(new ResponseType(), $response); $formData = json_decode($request->getContent(), true); $formData['application'] = $application->getId(); $form->submit($formData); if (!$form->isValid()) { return JsonResponse::create(array('status' => 'Error', 'message' => array_values($this->getErrorMessages($form))[0]), 400); } $em = $this->getDoctrine()->getManager(); $em->persist($response); $em->flush(); return $this->success($response, 'application', Response::HTTP_OK, array('Default', 'Details')); }