public function it_can_handle_exception_during_request(RequestInterface $request) { $uuid = Uuid::uuid4(); $request->offsetGet('uuid')->willReturn($uuid->toString()); $request->getAcceptContentType()->willReturn('text/xml'); $this->pageRepository->getByUuid($uuid)->willThrow(new \RuntimeException()); $this->shouldThrow(ResponseException::class)->duringExecuteRequest($request); }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $parentUuid = isset($request['parent_uuid']) ? Uuid::fromString($request['parent_uuid']) : null; return new Response(self::MESSAGE, ['data' => $this->pageRepository->getAllByParentUuid($parentUuid), 'parent_uuid' => $parentUuid, 'includes' => ['pageBlocks']], $request); } catch (\Throwable $e) { $this->log(LogLevel::ERROR, $e->getMessage()); throw new ResponseException('An error occurred during ListPagesHandler.', new ServerErrorResponse([], $request)); } }
/** {@inheritdoc} */ public function executeRequest(RequestInterface $request) : ResponseInterface { try { $page = new Page(Uuid::uuid4(), $request['title'], $request['slug'], $request['short_title'], $request['parent_uuid'] ? Uuid::fromString($request['parent_uuid']) : null, $request['sort_order'], PageStatusValue::get($request['status'])); $this->pageRepository->create($page); return new Response(self::MESSAGE, ['data' => $page], $request); } catch (\Throwable $exception) { $this->log(LogLevel::ERROR, $exception->getMessage()); throw new ResponseException('An error occurred during CreatePageHandler.', new ServerErrorResponse([], $request)); } }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $page = $this->pageRepository->getByUuid(Uuid::fromString($request['id'])); $this->applyRequestToPage($request['attributes'], $page); $this->pageRepository->update($page); return new Response(self::MESSAGE, ['data' => $page], $request); } catch (\Throwable $exception) { $this->log(LogLevel::ERROR, $exception->getMessage()); throw new ResponseException('An error occurred during UpdatePageHandler.', new ServerErrorResponse([], $request)); } }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $page = $this->pageRepository->getByUuid(Uuid::fromString($request['uuid'])); return new Response(self::MESSAGE, ['data' => $page, 'includes' => ['pageBlocks']], $request); } catch (NoUniqueResultException $e) { return new NotFoundResponse([], $request); } catch (\Throwable $e) { $this->log(LogLevel::ERROR, $e->getMessage()); throw new ResponseException('An error occurred during GetPageHandler.', new ServerErrorResponse([], $request)); } }
public function it_can_execute_a_request(RequestInterface $request) { $request->offsetGet('title')->willReturn('Long title'); $request->offsetGet('slug')->willReturn('long-title'); $request->offsetGet('short_title')->willReturn('Title'); $request->offsetGet('parent_uuid')->willReturn(null); $request->offsetGet('sort_order')->willReturn(42); $request->offsetGet('status')->willReturn('concept'); $request->getAcceptContentType()->willReturn('application/json'); $this->pageRepository->create(new Argument\Token\TypeToken(Page::class)); $response = $this->executeRequest($request); $response->shouldHaveType(ResponseInterface::class); $response['data']->shouldHaveType(Page::class); }
public function executeRequest(RequestInterface $request) : ResponseInterface { try { $page = $this->pageRepository->getByUuid(Uuid::fromString($request['id'])); $pageBlock = $this->createBlockFromRequest($request, $page); $this->pageRepository->addBlockToPage($pageBlock, $page); return new Response(self::MESSAGE, ['data' => $pageBlock, 'includes' => ['pages']], $request); } catch (NoResultException $exception) { return new NotFoundResponse([], $request); } catch (\Throwable $exception) { $this->log(LogLevel::ERROR, $exception->getMessage()); throw new ResponseException('An error occurred during AddPageBlockHandler.', new ServerErrorResponse([], $request)); } }