public function executeRequest(RequestInterface $request) : ResponseInterface { try { $page = $this->pageRepository->getByUuid(Uuid::fromString($request['page_uuid'])); $pageBlock = $page->getBlockByUuid(Uuid::fromString($request['uuid'])); $this->pageRepository->deleteBlockFromPage($pageBlock, $page); return new Response(self::MESSAGE, ['data' => $pageBlock], $request); } catch (NoResultException $e) { return new NotFoundResponse([], $request); } catch (\Throwable $e) { $this->log(LogLevel::ERROR, $e->getMessage()); throw new ResponseException('An error occurred during DeletePageBlockHandler.', new ServerErrorResponse([], $request)); } }
public function it_can_execute_a_request(RequestInterface $request, Page $page, PageBlock $block) { $pageUuid = Uuid::uuid4(); $blockUuid = Uuid::uuid4(); $request->offsetGet('uuid')->willReturn($blockUuid->toString()); $request->offsetGet('page_uuid')->willReturn($pageUuid->toString()); $request->getAcceptContentType()->willReturn('text/xml'); $this->pageRepository->getByUuid($pageUuid)->willReturn($page); $page->getBlockByUuid($blockUuid)->willReturn($block); $this->pageRepository->deleteBlockFromPage($block, $page)->shouldBeCalled(); $response = $this->executeRequest($request); $response->shouldHaveType(ResponseInterface::class); $response->getResponseName()->shouldReturn(DeletePageBlockHandler::MESSAGE); $response['data']->shouldBe($block); }