From 86ce06f347728ee15eb9e123c16d96bc7d1f1b1f Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 21 May 2024 09:50:28 +0200 Subject: [PATCH] Backport test for Query::setLockMode() --- tests/Tests/ORM/Query/QueryTest.php | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Tests/ORM/Query/QueryTest.php b/tests/Tests/ORM/Query/QueryTest.php index 7a1ffa0d702..b1c72f4ad14 100644 --- a/tests/Tests/ORM/Query/QueryTest.php +++ b/tests/Tests/ORM/Query/QueryTest.php @@ -13,10 +13,13 @@ use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\LockMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Types; use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Internal\Hydration\IterableResult; +use Doctrine\ORM\Query; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\UnitOfWork; @@ -88,6 +91,33 @@ public function testSetParameters(): void self::assertEquals($parameters, $query->getParameters()); } + /** + * @psalm-param LockMode::* $lockMode + * + * @dataProvider provideLockModes + */ + public function testSetLockMode(int $lockMode): void + { + $query = $this->entityManager->wrapInTransaction(static function (EntityManagerInterface $em) use ($lockMode): Query { + $query = $em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1'); + $query->setLockMode($lockMode); + + return $query; + }); + + self::assertSame($lockMode, $query->getLockMode()); + self::assertSame($lockMode, $query->getHint(Query::HINT_LOCK_MODE)); + } + + /** @psalm-return list */ + public static function provideLockModes(): array + { + return [ + [LockMode::PESSIMISTIC_READ], + [LockMode::PESSIMISTIC_WRITE], + ]; + } + public function testFree(): void { $query = $this->entityManager->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1');