Skip to content

Commit a0ed379

Browse files
authored
Merge pull request #11167 from bobvandevijver/fix-eager-iterable-loading-test
Use foreach on iterable to prevent table locks during tests
2 parents 398ab05 + 4875f4c commit a0ed379

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/Doctrine/Tests/ORM/Functional/EagerFetchCollectionTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ protected function setUp(): void
1818
parent::setUp();
1919

2020
$this->createSchemaForModels(EagerFetchOwner::class, EagerFetchChild::class);
21+
22+
// Ensure tables are empty
23+
$this->_em->getRepository(EagerFetchChild::class)->createQueryBuilder('o')->delete()->getQuery()->execute();
24+
$this->_em->getRepository(EagerFetchOwner::class)->createQueryBuilder('o')->delete()->getQuery()->execute();
2125
}
2226

2327
public function testEagerFetchMode(): void
@@ -91,9 +95,11 @@ public function testEagerFetchWithIterable(): void
9195
$this->_em->clear();
9296

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

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

99105
protected function createOwnerWithChildren(int $children): EagerFetchOwner

0 commit comments

Comments
 (0)