Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use foreach on iterable to prevent table locks during tests #11167

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading