function it_dispatches_an_event_when_removing_a_tree($eventDispatcher, $objectManager, CategoryInterface $tree) { $tree->isRoot()->willReturn(true); $tree->getProducts()->willReturn([]); $eventDispatcher->dispatch(CategoryEvents::PRE_REMOVE_TREE, Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled(); $objectManager->remove($tree)->shouldBeCalled(); $this->remove($tree, ['flush' => false]); }
function it_dispatches_an_event_when_removing_a_tree($eventDispatcher, $objectManager, CategoryInterface $tree) { $tree->getId()->willReturn(12); $tree->isRoot()->willReturn(true); $tree->getProducts()->willReturn([]); $eventDispatcher->dispatch(CategoryEvents::PRE_REMOVE_TREE, Argument::type('Akeneo\\Component\\StorageUtils\\Event\\RemoveEvent'))->shouldBeCalled(); $objectManager->remove($tree)->shouldBeCalled(); $eventDispatcher->dispatch(CategoryEvents::POST_REMOVE_TREE, Argument::type('Akeneo\\Component\\StorageUtils\\Event\\RemoveEvent'))->shouldBeCalled(); $this->remove($tree, ['flush' => true]); }
/** * Remove a category * * @param CategoryInterface $category * * @deprecated will be removed in 1.4, replaced by CategoryRemover::remove */ public function remove(CategoryInterface $category) { foreach ($category->getProducts() as $product) { $product->removeCategory($category); } $this->getObjectManager()->remove($category); }
function it_does_not_mark_products_as_updated_when_a_category_is_updated(EntityManager $em, ProductInterface $foo, ProductInterface $bar, CategoryInterface $category) { $category->getProducts()->willReturn([$foo, $bar]); $this->guessUpdates($em, $category, UpdateGuesserInterface::ACTION_UPDATE_ENTITY)->shouldReturn([]); }
/** * Remove a category * * @param CategoryInterface $category */ public function remove(CategoryInterface $category) { $eventName = $category->isRoot() ? CategoryEvents::PRE_REMOVE_TREE : CategoryEvents::PRE_REMOVE_CATEGORY; $this->eventDispatcher->dispatch($eventName, new GenericEvent($category)); foreach ($category->getProducts() as $product) { $product->removeCategory($category); } $this->getObjectManager()->remove($category); }