public function it_throws_exception_if_item_after_moved_item_should_be_placed_does_not_exist(MenuItemInterface $sourceItem, MenuItemInterface $parentItem, MenuItemInterface $afterItem, MenuItemRepositoryInterface $menuItemRepository, ObjectManager $objectManager) { $sourceItem->getPosition()->willReturn(1); $menuItemRepository->findChildByParentAndPosition($parentItem, 2)->willReturn(null); $menuItemRepository->persistAsNextSiblingOf($sourceItem, $afterItem)->shouldNotBeCalled(); $sourceItem->getPosition()->shouldBeCalled(); $sourceItem->setPosition(2)->shouldNotBeCalled(); $objectManager->flush()->shouldNotBeCalled(); $this->shouldThrow(HttpException::class)->duringMove($sourceItem, $parentItem, 2); }
private function ensurePositionIsValid(MenuItemInterface $menuItem, int $position) { if ($menuItem->getPosition() === $position) { throw new ConflictHttpException(sprintf('Menu item %d is already placed at position %d.', $menuItem->getId(), $position)); } }