From 5034da73cf834e746c6e584458881fcfef436cd7 Mon Sep 17 00:00:00 2001 From: DjLeChuck Date: Sat, 18 May 2019 11:51:56 +0200 Subject: [PATCH 1/3] Add missing cascade persist on relations --- .../Translatable/TranslatableManyToManyBidirectionalParent.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php b/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php index 076f367..9d1dbdb 100644 --- a/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php +++ b/tests/Fixtures/AppTestBundle/Entity/Translatable/TranslatableManyToManyBidirectionalParent.php @@ -29,6 +29,7 @@ class TranslatableManyToManyBidirectionalParent implements TranslatableInterface * * @ORM\ManyToMany( * targetEntity="AppTestBundle\Entity\Translatable\TranslatableManyToManyBidirectionalChild", + * cascade={"persist"}, * mappedBy="simpleParents" * ) */ @@ -39,6 +40,7 @@ class TranslatableManyToManyBidirectionalParent implements TranslatableInterface * * @ORM\ManyToMany( * targetEntity="AppTestBundle\Entity\Translatable\TranslatableManyToManyBidirectionalChild", + * cascade={"persist"}, * mappedBy="emptyParents" * ) * @ORM\JoinTable(name="empty_translatablemanytomanybidirectionalchild_translatablemanytomanybidirectionalparent") From 6e6c0b782c88d173ba32ef8413160f165c4fe0b9 Mon Sep 17 00:00:00 2001 From: DjLeChuck Date: Sat, 18 May 2019 11:52:49 +0200 Subject: [PATCH 2/3] TranslatableEntityHandler should not automatically persists the entity --- src/Translation/Handlers/TranslatableEntityHandler.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Translation/Handlers/TranslatableEntityHandler.php b/src/Translation/Handlers/TranslatableEntityHandler.php index 8ac03db..877ffa8 100644 --- a/src/Translation/Handlers/TranslatableEntityHandler.php +++ b/src/Translation/Handlers/TranslatableEntityHandler.php @@ -71,8 +71,6 @@ public function translate(TranslationArgs $args) $clone->setLocale($args->getTargetLocale()); - $this->em->persist($clone); - return $clone; } From 7010a7a1ba2c09060ada30d0b1be84bb9aaa4877 Mon Sep 17 00:00:00 2001 From: DjLeChuck Date: Sat, 18 May 2019 11:54:09 +0200 Subject: [PATCH 3/3] Fix tests: Manually call persist on translated entities --- tests/ScalarTranslationTest.php | 2 ++ tests/TranslatableManyToOneEntityTranslationTest.php | 3 +++ tests/TranslatableOneToOneUnidirectionalTest.php | 1 + 3 files changed, 6 insertions(+) diff --git a/tests/ScalarTranslationTest.php b/tests/ScalarTranslationTest.php index 6780f79..1c782e3 100644 --- a/tests/ScalarTranslationTest.php +++ b/tests/ScalarTranslationTest.php @@ -17,6 +17,7 @@ public function it_can_translate_scalar_value() { $entity = $this->createEntity(); $translation = $this->translator->translate($entity, 'fr'); + $this->em->persist($translation); $this->em->flush(); $this->assertAttributeContains('Test title', 'title', $translation); $this->assertIsTranslation($entity, $translation); @@ -48,6 +49,7 @@ public function it_can_empty_scalar_value_on_translate() $entity = $this->createEntity(); $translation = $this->translator->translate($entity, 'fr'); + $this->em->persist($translation); $this->em->flush(); $this->assertAttributeEmpty('empty', $translation); $this->assertIsTranslation($entity, $translation); diff --git a/tests/TranslatableManyToOneEntityTranslationTest.php b/tests/TranslatableManyToOneEntityTranslationTest.php index 10295dc..18e6ddb 100644 --- a/tests/TranslatableManyToOneEntityTranslationTest.php +++ b/tests/TranslatableManyToOneEntityTranslationTest.php @@ -27,6 +27,7 @@ public function it_can_translate_simple_value() /** @var TranslatableManyToOne $translation */ $translation = $this->translator->translate($entity, self::TARGET_LOCALE); + $this->em->persist($translation); $this->em->flush(); $this->assertNotEquals($associatedEntity, $translation->getSimple()); $this->assertAttributeContains(self::TARGET_LOCALE, 'locale', $translation->getSimple()); @@ -41,6 +42,7 @@ public function it_must_associate_existing_translation() $this->em->persist($associatedEntity); $translatedAssociatedEntity = $this->translator->translate($associatedEntity, self::TARGET_LOCALE); + $this->em->persist($translatedAssociatedEntity); $entity = (new TranslatableManyToOne()) @@ -52,6 +54,7 @@ public function it_must_associate_existing_translation() /** @var TranslatableManyToOne $translation */ $translation = $this->translator->translate($entity, self::TARGET_LOCALE); + $this->em->persist($translation); $this->em->flush(); $this->assertNotEquals($associatedEntity, $translation->getSimple()); $this->assertEquals($translatedAssociatedEntity, $translation->getSimple()); diff --git a/tests/TranslatableOneToOneUnidirectionalTest.php b/tests/TranslatableOneToOneUnidirectionalTest.php index fd8c0ed..e6e3300 100644 --- a/tests/TranslatableOneToOneUnidirectionalTest.php +++ b/tests/TranslatableOneToOneUnidirectionalTest.php @@ -27,6 +27,7 @@ public function it_can_translate_simple_value() /** @var TranslatableOneToOneUnidirectional $translation */ $translation = $this->translator->translate($entity, self::TARGET_LOCALE); + $this->em->persist($translation); $this->em->flush(); $this->assertNotEquals($associatedEntity, $translation->getSimple()); $this->assertAttributeContains(self::TARGET_LOCALE, 'locale', $translation->getSimple());