public function it_will_roll_back_when_update_a_block_fails(Page $page, PageBlock $block) { $uuid = Uuid::uuid4(); $page->getUuid()->willReturn($uuid); $blockUuid = Uuid::uuid4(); $block->getUuid()->willReturn($blockUuid); $block->getPage()->willReturn($page); $this->pdo->beginTransaction()->shouldBeCalled(); $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE page_blocks'))->willThrow(new \RuntimeException()); $this->pdo->rollBack()->shouldBeCalled(); $this->shouldThrow(\RuntimeException::class)->duringUpdateBlockForPage($block, $page); }
public function deleteBlockFromPage(PageBlock $block, Page $page) { if (!$page->getUuid()->equals($block->getPage()->getUuid())) { throw new \OutOfBoundsException('PageBlock must belong to page to be added to it.'); } // The database constraint should cascade the delete to the page $this->objectRepository->delete(PageBlock::TYPE, $block->getUuid()); $page->removeBlock($block); $this->objectRepository->update(Page::TYPE, $page->getUuid()); $page->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); $block->setStatus(PageStatusValue::get(PageStatusValue::DELETED)); }
public function it_can_give_an_entities_id() { $this->getId($this->block)->shouldReturn($this->block->getUuid()->toString()); }
public function it_errors_when_a_specific_block_does_not_exist(PageBlock $block1, PageBlock $block2, PageBlock $block3) { $uuid1 = Uuid::uuid4(); $block1->getUuid()->willReturn($uuid1); $block1->getSortOrder()->willReturn(1); $uuid2 = Uuid::uuid4(); $block2->getUuid()->willReturn($uuid2); $block2->getSortOrder()->willReturn(2); $uuid3 = Uuid::uuid4(); $block3->getUuid()->willReturn($uuid3); $block3->getSortOrder()->willReturn(3); $this->setBlocks([$block1, $block2, $block3])->shouldReturn($this); $this->shouldThrow(NoResultException::class)->duringGetBlockByUuid(Uuid::uuid4()); }
public function removeBlock(PageBlock $block) : Page { foreach ($this->getBlocks() as $idx => $relBlock) { if ($relBlock->getUuid()->equals($block->getUuid())) { unset($this->relatedBlocks[$idx]); $this->relatedBlocks = array_merge($this->relatedBlocks); return $this; } } throw new NoResultException('Block not found in Page\'s blocks: ' . $block->getUuid()->toString()); }