Skip to content

Commit

Permalink
move test to avoid weird issue with unit of work and php 8 ?
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Apr 19, 2021
1 parent 98c0c61 commit 9937a0e
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions tests/Bridge/Doctrine/Persister/ObjectManagerPersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function setUp(): void
*/
public function tearDown(): void
{
$this->entityManager->getUnitOfWork()->clear();
$this->purger->purge();
}

Expand Down Expand Up @@ -114,6 +113,28 @@ public function testCanPersistAnEntity($entity, bool $exact = false)
}
}

public function testCanPersistEntitiesWithoutExplicitIdentifierSetEvenWhenExistingEntitiesHaveOne()
{
$dummy1 = new Dummy();
$this->entityManager->persist($dummy1);
$this->entityManager->flush();

// When loading fixtures in real world and existing entity can be persisted again by the persister.
// e.g. when this entity has been persisted by a relation with the cascade persist option.
$this->persister->persist($dummy1);

$dummy2 = new Dummy();
$this->persister->persist($dummy2);

$this->persister->flush();

$entity = $this->entityManager->getRepository(Dummy::class)->find($dummy1->id);
$this->assertInstanceOf(Dummy::class, $entity);

$entity = $this->entityManager->getRepository(Dummy::class)->find($dummy2->id);
$this->assertInstanceOf(Dummy::class, $entity);
}

public function testCanPersistAnEntityWithRelationsAndExplicitIds()
{
$dummy = new DummyWithIdentifier();
Expand Down Expand Up @@ -170,28 +191,6 @@ public function testCanPersistMultipleEntitiesWithExplicitIdentifierSet()
$this->assertInstanceOf(DummyWithIdentifier::class, $entity);
}

public function testCanPersistEntitiesWithoutExplicitIdentifierSetEvenWhenExistingEntitiesHaveOne()
{
$dummy1 = new Dummy();
$this->entityManager->persist($dummy1);
$this->entityManager->flush();

// When loading fixtures in real world and existing entity can be persisted again by the persister.
// e.g. when this entity has been persisted by a relation with the cascade persist option.
$this->persister->persist($dummy1);

$dummy2 = new Dummy();
$this->persister->persist($dummy2);

$this->persister->flush();

$entity = $this->entityManager->getRepository(Dummy::class)->find($dummy1->id);
$this->assertInstanceOf(Dummy::class, $entity);

$entity = $this->entityManager->getRepository(Dummy::class)->find($dummy2->id);
$this->assertInstanceOf(Dummy::class, $entity);
}

public function testPersistingMultipleEntitiesWithAndWithoutExplicitIdentifierSetWillNotThrowORMException()
{
$dummy = new DummyWithIdentifier();
Expand Down

0 comments on commit 9937a0e

Please sign in to comment.