Skip to content

Commit

Permalink
Merge pull request #11167 from bobvandevijver/fix-eager-iterable-load…
Browse files Browse the repository at this point in the history
…ing-test

Use foreach on iterable to prevent table locks during tests
  • Loading branch information
greg0ire authored Jan 18, 2024
2 parents 398ab05 + 4875f4c commit a0ed379
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/Doctrine/Tests/ORM/Functional/EagerFetchCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ protected function setUp(): void
parent::setUp();

$this->createSchemaForModels(EagerFetchOwner::class, EagerFetchChild::class);

// Ensure tables are empty
$this->_em->getRepository(EagerFetchChild::class)->createQueryBuilder('o')->delete()->getQuery()->execute();
$this->_em->getRepository(EagerFetchOwner::class)->createQueryBuilder('o')->delete()->getQuery()->execute();
}

public function testEagerFetchMode(): void
Expand Down Expand Up @@ -91,9 +95,11 @@ public function testEagerFetchWithIterable(): void
$this->_em->clear();

$iterable = $this->_em->getRepository(EagerFetchOwner::class)->createQueryBuilder('o')->getQuery()->toIterable();
$owner = $iterable->current();

$this->assertCount(2, $owner->children);
// There is only a single record, but use a foreach to ensure the iterator is marked as finished and the table lock is released
foreach ($iterable as $owner) {
$this->assertCount(2, $owner->children);
}
}

protected function createOwnerWithChildren(int $children): EagerFetchOwner
Expand Down

0 comments on commit a0ed379

Please sign in to comment.