/** * @param ProductTranslationInterface $object */ private function updateSlug(ProductTranslationInterface $object) { $slug = $this->slugify($object->getName()); $object->setSlug($slug); }
function it_does_not_generate_duplicated_slugs_based_on_database_when_updating(LifecycleEventArgs $lifecycleEventArgs, ObjectManager $objectManager, ProductTranslationInterface $productTranslation, ObjectRepository $productTranslationRepository) { $lifecycleEventArgs->getObjectManager()->willReturn($objectManager); $objectManager->getRepository(get_class($productTranslation->getWrappedObject()))->willReturn($productTranslationRepository); $lifecycleEventArgs->getObject()->willReturn($productTranslation); $productTranslation->getName()->willReturn('Banana'); $productTranslationRepository->findOneBy(['slug' => 'banana'])->willReturn(new \stdClass()); $productTranslationRepository->findOneBy(['slug' => 'banana-1'])->willReturn(null); $productTranslation->setSlug('banana-1')->shouldBeCalled(); $this->preUpdate($lifecycleEventArgs); }