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');