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 it_can_execute_a_request_part_deux(RequestInterface $request, Page $page) { $pageUuid = Uuid::uuid4(); $attributes = ['sort_order' => $sortOrder = 3, 'status' => PageStatusValue::CONCEPT]; $request->offsetGet('id')->willReturn($pageUuid->toString()); $request->offsetGet('attributes')->willReturn($attributes); $request->getAcceptContentType()->willReturn('text/xml'); $this->pageRepository->getByUuid($pageUuid)->willReturn($page); $page->setSortOrder($sortOrder)->shouldBeCalled(); $page->setStatus(PageStatusValue::get($attributes['status']))->shouldBeCalled(); $this->pageRepository->update($page)->shouldBeCalled(); $response = $this->executeRequest($request); $response['data']->shouldBe($page); }
public function it_can_execute_request_with_null_parent(RequestInterface $request, Page $page1, Page $page2) { $parentUuid = null; $page1Uuid = Uuid::uuid4(); $page1->getUuid()->willReturn($page1Uuid); $page1->getParentUuid()->willReturn(null); $page1->getSortOrder()->willReturn(1); $page1->setSortOrder(2)->shouldBeCalled(); $page2Uuid = Uuid::uuid4(); $page2->getUuid()->willReturn($page2Uuid); $page2->getParentUuid()->willReturn(null); $page2->getSortOrder()->willReturn(2); $page2->setSortOrder(1)->shouldBeCalled(); $this->pageRepository->getByUuid($page1Uuid)->willReturn($page1); $this->pageRepository->getByUuid($page2Uuid)->willReturn($page2); $this->pageRepository->update($page1)->shouldBeCalled(); $this->pageRepository->update($page2)->shouldBeCalled(); $orderedPageUuids = [['page_uuid' => $page2Uuid->toString()], ['page_uuid' => $page1Uuid->toString()]]; $request->getAcceptContentType()->willReturn('*/*'); $request->offsetGet('ordered_pages')->willReturn($orderedPageUuids); $request->offsetGet('parent_uuid')->willReturn($parentUuid); $response = $this->executeRequest($request); $response->shouldHaveType(ResponseInterface::class); $response['data']->shouldBe([$page2, $page1]); }