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

Fix return type of Query::getLockMode() for DBAL 4 #11462

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,10 @@ public function setLockMode(LockMode|int $lockMode): self
/**
* Get the current lock mode for this query.
*
* @return int|null The current lock mode of this query or NULL if no specific lock mode is set.
* @return LockMode|int|null The current lock mode of this query or NULL if no specific lock mode is set.
* @psalm-return LockMode::*|null
*/
public function getLockMode(): int|null
public function getLockMode(): LockMode|int|null
{
$lockMode = $this->getHint(self::HINT_LOCK_MODE);

Expand Down
30 changes: 28 additions & 2 deletions tests/Tests/ORM/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\UnitOfWork;
Expand All @@ -39,8 +42,7 @@

class QueryTest extends OrmTestCase
{
/** @var EntityManagerMock */
protected $entityManager;
private EntityManagerMock $entityManager;

protected function setUp(): void
{
Expand Down Expand Up @@ -80,6 +82,30 @@ public function testSetParameters(): void
self::assertEquals($parameters, $query->getParameters());
}

/** @psalm-param LockMode::* $lockMode */
#[DataProvider('provideLockModes')]
public function testSetLockMode(LockMode|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<array{LockMode::*}> */
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');
Expand Down
Loading