/** * @param Request $request * @return JsonResponse */ public function uploadComposerAction(Request $request) { $this->composerForm->handleRequest($request); if ($this->composerForm->isValid()) { $data = $this->composerForm->getData(); $this->sonataNotificationsBackend->createAndPublish('upload.composer', array('body' => $data['body'], 'channelName' => $request->getSession()->get('channelName'), 'hasDevDependencies' => $data['hasDevDependencies'])); return new JsonResponse(array('status' => 'ok')); } $errors = array_map(function (FormError $error) { return $error->getMessage(); }, $this->composerForm->get('body')->getErrors()); return new JsonResponse(array('status' => 'ko', 'message' => $errors)); }
/** * @return AMQPChannel */ protected function getChannel() { if ($this->dispatcher === null) { throw new \RuntimeException('Unable to retrieve AMQP channel without dispatcher.'); } return $this->dispatcher->getChannel(); }
public function it_return_json_with_success_status_and_create_sonata_notification(Request $request, Session $session, Form $composerForm, AMQPBackendDispatcher $sonataNotificationsBackend) { $composerJsonContent = <<<'EOT' { "require": { "monolog/monolog": "1.2.*" } } EOT; $composerForm->handleRequest($request)->shouldBeCalled(); $composerForm->isValid()->shouldBeCalled()->willReturn(true); $composerForm->getData()->shouldBeCalled()->willReturn(array('body' => $composerJsonContent, 'hasDevDependencies' => false)); $request->getSession()->shouldBeCalled()->willReturn($session); $session->get('channelName')->shouldBeCalled()->willReturn('example_channel_name'); $sonataNotificationsBackend->createAndPublish('upload.composer', array('body' => $composerJsonContent, 'channelName' => 'example_channel_name', 'hasDevDependencies' => false))->shouldBeCalled(); $this->uploadComposerAction($request)->shouldBeJsonResponse(array('status' => 'ok')); }