diff --git a/fixtures/Bridge/Doctrine/Entity/DummyWithProperty.php b/fixtures/Bridge/Doctrine/Entity/DummyWithProperty.php new file mode 100644 index 00000000..6ec0cc54 --- /dev/null +++ b/fixtures/Bridge/Doctrine/Entity/DummyWithProperty.php @@ -0,0 +1,30 @@ +metadataToRestore as $metadata) { $metadataFactory->setMetadataFor($metadata->getName(), $metadata); + $this->clearUnitOfWorkPersister($metadata->getName()); } $this->metadataToRestore = []; diff --git a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php index ef10b37a..d602cf55 100644 --- a/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php +++ b/tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php @@ -21,6 +21,7 @@ use Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\DummySubClass; use Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\DummyWithEmbeddable; use Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\DummyWithIdentifier; +use Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\DummyWithProperty; use Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\DummyWithRelatedCascadePersist; use Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\DummyWithRelation; use Fidry\AliceDataFixtures\Bridge\Doctrine\Entity\MappedSuperclassDummy; @@ -140,6 +141,24 @@ public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet(): void self::assertInstanceOf(DummyWithIdentifier::class, $entity); } + public function testClearingUnitOfWorkPersister(): void + { + $dummy = new DummyWithProperty(); + $dummy->id = 1; + + $this->persister->persist($dummy); + $this->persister->flush(); + + $dummy = new DummyWithProperty(); + $dummy->property = 'foo'; + + $this->entityManager->persist($dummy); + $this->entityManager->flush(); + + $entity = $this->entityManager->getRepository(DummyWithProperty::class)->findOneBy(['property' => 'foo']); + self::assertInstanceOf(DummyWithProperty::class, $entity); + } + public function testCanPersistEntitiesWithoutExplicitIdentifierSetEvenWhenExistingEntitiesHaveOne(): void { $dummy1 = new Dummy();