Skip to content

Commit

Permalink
Merge branch '2.19.x' into 2.20.x
Browse files Browse the repository at this point in the history
* 2.19.x:
  Psalm 5.24.0 (#11467)
  PHPStan 1.11.1 (#11466)
  Test with actual lock modes (#11465)
  Backport test for Query::setLockMode() (#11463)
  • Loading branch information
derrabus committed May 21, 2024
2 parents eb49f66 + d31aabb commit bf3e082
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"doctrine/annotations": "^1.13 || ^2",
"doctrine/coding-standard": "^9.0.2 || ^12.0",
"phpbench/phpbench": "^0.16.10 || ^1.0",
"phpstan/phpstan": "~1.4.10 || 1.10.59",
"phpstan/phpstan": "~1.4.10 || 1.11.1",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.6",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.2",
"symfony/cache": "^4.4 || ^5.4 || ^6.4 || ^7.0",
"symfony/var-exporter": "^4.4 || ^5.4 || ^6.2 || ^7.0",
"symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0",
"vimeo/psalm": "4.30.0 || 5.22.2"
"vimeo/psalm": "4.30.0 || 5.24.0"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 3.0"
Expand Down
13 changes: 9 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.22.2@d768d914152dbbf3486c36398802f74e80cfde48">
<files psalm-version="5.24.0@462c80e31c34e58cc4f750c656be3927e80e550e">
<file src="src/AbstractQuery.php">
<DeprecatedClass>
<code><![CDATA[IterableResult]]></code>
Expand Down Expand Up @@ -380,6 +380,9 @@
<code><![CDATA[serialize]]></code>
<code><![CDATA[unserialize]]></code>
</MethodSignatureMustProvideReturnType>
<ParamNameMismatch>
<code><![CDATA[$serialized]]></code>
</ParamNameMismatch>
</file>
<file src="src/Id/TableGenerator.php">
<PossiblyFalseOperand>
Expand Down Expand Up @@ -2341,9 +2344,6 @@
<InvalidReturnType>
<code><![CDATA[ObjectRepository]]></code>
</InvalidReturnType>
<TypeDoesNotContainType>
<code><![CDATA[$repository instanceof EntityRepository]]></code>
</TypeDoesNotContainType>
<UnsafeInstantiation>
<code><![CDATA[new $repositoryClassName($entityManager, $metadata)]]></code>
</UnsafeInstantiation>
Expand Down Expand Up @@ -2514,6 +2514,11 @@
<PossiblyNullArgument>
<code><![CDATA[$variableType]]></code>
</PossiblyNullArgument>
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$fieldMapping['declaredField']]]></code>
<code><![CDATA[$fieldMapping['declaredField']]]></code>
<code><![CDATA[$fieldMapping['declaredField']]]></code>
</PossiblyUndefinedArrayOffset>
<PropertyNotSetInConstructor>
<code><![CDATA[$classToExtend]]></code>
</PropertyNotSetInConstructor>
Expand Down
21 changes: 15 additions & 6 deletions tests/Tests/ORM/Cache/Persister/Entity/EntityPersisterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\Cache\Persister\CachedPersister;
use Doctrine\ORM\Cache\Persister\Entity\AbstractEntityPersister;
use Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function testInvokeGetSelectSQL(): void
->with(
self::identicalTo(['name' => 'Foo']),
self::identicalTo([0]),
self::identicalTo(1),
self::identicalTo(LockMode::OPTIMISTIC),
self::identicalTo(2),
self::identicalTo(3),
self::identicalTo([4])
Expand All @@ -109,7 +110,7 @@ public function testInvokeGetSelectSQL(): void
self::assertSame('SELECT * FROM foo WERE name = ?', $persister->getSelectSQL(
['name' => 'Foo'],
[0],
1,
LockMode::OPTIMISTIC,
2,
3,
[4]
Expand Down Expand Up @@ -228,13 +229,21 @@ public function testInvokeLoad(): void
self::identicalTo($entity),
self::identicalTo([0]),
self::identicalTo([1]),
self::identicalTo(2),
self::identicalTo(LockMode::PESSIMISTIC_READ),
self::identicalTo(3),
self::identicalTo([4])
)
->willReturn($entity);

self::assertSame($entity, $persister->load(['id' => 1], $entity, [0], [1], 2, 3, [4]));
self::assertSame($entity, $persister->load(
['id' => 1],
$entity,
[0],
[1],
LockMode::PESSIMISTIC_READ,
3,
[4]
));
}

public function testInvokeLoadAll(): void
Expand Down Expand Up @@ -391,9 +400,9 @@ public function testInvokeLock(): void

$this->entityPersister->expects(self::once())
->method('lock')
->with(self::identicalTo($identifier), self::identicalTo(1));
->with(self::identicalTo($identifier), self::identicalTo(LockMode::OPTIMISTIC));

$persister->lock($identifier, 1);
$persister->lock($identifier, LockMode::OPTIMISTIC);
}

public function testInvokeExists(): void
Expand Down
30 changes: 30 additions & 0 deletions tests/Tests/ORM/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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

0 comments on commit bf3e082

Please sign in to comment.