diff --git a/lib/Doctrine/ORM/LazyCriteriaCollection.php b/lib/Doctrine/ORM/LazyCriteriaCollection.php
index 7fb866c48d2..2e298f77f70 100644
--- a/lib/Doctrine/ORM/LazyCriteriaCollection.php
+++ b/lib/Doctrine/ORM/LazyCriteriaCollection.php
@@ -9,6 +9,7 @@
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Persisters\Entity\EntityPersister;
+use ReturnTypeWillChange;
/**
* A lazy collection that allows a fast count when using criteria object
@@ -38,6 +39,7 @@ public function __construct(EntityPersister $entityPersister, Criteria $criteria
*
* @return int
*/
+ #[ReturnTypeWillChange]
public function count()
{
if ($this->isInitialized()) {
diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php
index 5ac43b0b7cd..89f6710b6eb 100644
--- a/lib/Doctrine/ORM/PersistentCollection.php
+++ b/lib/Doctrine/ORM/PersistentCollection.php
@@ -10,6 +10,7 @@
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping\ClassMetadata;
+use ReturnTypeWillChange;
use RuntimeException;
use function array_combine;
@@ -504,6 +505,7 @@ public function offsetSet($offset, $value): void
*
* @return object|null
*/
+ #[ReturnTypeWillChange]
public function offsetUnset($offset)
{
return $this->remove($offset);
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 33d984500b0..255f15da3c2 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -265,16 +265,6 @@ parameters:
count: 2
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
- -
- message: "#^Call to an undefined method ReflectionProperty\\:\\:getType\\(\\)\\.$#"
- count: 3
- path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
-
- -
- message: "#^Call to an undefined method ReflectionProperty\\:\\:hasType\\(\\)\\.$#"
- count: 1
- path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
-
-
message: "#^Method Doctrine\\\\ORM\\\\Mapping\\\\NamingStrategy\\:\\:joinColumnName\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 2
@@ -1001,18 +991,17 @@ parameters:
path: lib/Doctrine/ORM/Query/Parser.php
-
- message:
- """
- #^PHPDoc tag @return has invalid value \\(AST\\\\BetweenExpression\\|
- AST\\\\CollectionMemberExpression\\|
- AST\\\\ComparisonExpression\\|
- AST\\\\EmptyCollectionComparisonExpression\\|
- AST\\\\ExistsExpression\\|
- AST\\\\InExpression\\|
- AST\\\\InstanceOfExpression\\|
- AST\\\\LikeExpression\\|
- AST\\\\NullComparisonExpression\\)\\: Unexpected token "\\\\n \\* ", expected type at offset 344$#
- """
+ message: """
+ #^PHPDoc tag @return has invalid value \\(AST\\\\BetweenExpression\\|
+ AST\\\\CollectionMemberExpression\\|
+ AST\\\\ComparisonExpression\\|
+ AST\\\\EmptyCollectionComparisonExpression\\|
+ AST\\\\ExistsExpression\\|
+ AST\\\\InExpression\\|
+ AST\\\\InstanceOfExpression\\|
+ AST\\\\LikeExpression\\|
+ AST\\\\NullComparisonExpression\\)\\: Unexpected token "\\\\n \\* ", expected type at offset 344$#
+ """
count: 1
path: lib/Doctrine/ORM/Query/Parser.php
@@ -1915,4 +1904,3 @@ parameters:
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$subClasses\\.$#"
count: 1
path: lib/Doctrine/ORM/Utility/HierarchyDiscriminatorResolver.php
-
diff --git a/phpstan-params.neon b/phpstan-params.neon
index 1a5e688fa43..784f63e2d2b 100644
--- a/phpstan-params.neon
+++ b/phpstan-params.neon
@@ -8,4 +8,4 @@ parameters:
earlyTerminatingMethodCalls:
Doctrine\ORM\Query\Parser:
- syntaxError
- phpVersion: 70100
+ phpVersion: 80100
diff --git a/psalm.xml b/psalm.xml
index 655c5be07ec..75039c541c7 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,6 +1,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php
index 3ee350e15a0..00c3e754ef9 100644
--- a/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php
+++ b/tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php
@@ -21,7 +21,7 @@ class CacheLoggerChainTest extends DoctrineTestCase
/** @var CacheLoggerChain */
private $logger;
- /** @var MockObject|CacheLogger */
+ /** @var CacheLogger&MockObject */
private $mock;
protected function setUp(): void
diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php
index accad3ce3f3..88f3fa10205 100644
--- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php
+++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php
@@ -31,6 +31,7 @@
use Doctrine\Tests\OrmTestCase;
use InvalidArgumentException;
use LogicException;
+use PHPUnit\Framework\MockObject\MockObject;
use function assert;
@@ -39,7 +40,7 @@
*/
class DefaultCacheFactoryTest extends OrmTestCase
{
- /** @var CacheFactory */
+ /** @var CacheFactory&MockObject */
private $factory;
/** @var EntityManager */
diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php
index 59d8178cd06..75bded05593 100644
--- a/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php
+++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Collection/AbstractCollectionPersisterTest.php
@@ -14,13 +14,14 @@
use Doctrine\ORM\Persisters\Collection\CollectionPersister;
use Doctrine\Tests\Models\Cache\State;
use Doctrine\Tests\OrmTestCase;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* @group DDC-2183
*/
abstract class AbstractCollectionPersisterTest extends OrmTestCase
{
- /** @var Region */
+ /** @var Region&MockObject */
protected $region;
/** @var CollectionPersister */
@@ -70,6 +71,9 @@ protected function setUp(): void
->getMock();
}
+ /**
+ * @return Region&MockObject
+ */
protected function createRegion(): Region
{
return $this->getMockBuilder(Region::class)
diff --git a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php
index 44c20d30489..b387e46826e 100644
--- a/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php
+++ b/tests/Doctrine/Tests/ORM/Cache/Persister/Entity/AbstractEntityPersisterTest.php
@@ -17,16 +17,17 @@
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\Tests\Models\Cache\Country;
use Doctrine\Tests\OrmTestCase;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* @group DDC-2183
*/
abstract class AbstractEntityPersisterTest extends OrmTestCase
{
- /** @var Region */
+ /** @var Region&MockObject */
protected $region;
- /** @var EntityPersister */
+ /** @var EntityPersister&MockObject */
protected $entityPersister;
/** @var EntityManager */
@@ -45,6 +46,9 @@ protected function setUp(): void
$this->entityPersister = $this->createMock(EntityPersister::class);
}
+ /**
+ * @return Region&MockObject
+ */
protected function createRegion(): Region
{
return $this->createMock(Region::class);
diff --git a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php
index 400dbfe42fb..4600871065d 100644
--- a/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php
+++ b/tests/Doctrine/Tests/ORM/Decorator/EntityManagerDecoratorTest.php
@@ -32,7 +32,7 @@ class EntityManagerDecoratorTest extends TestCase
'lock',
];
- /** @var EntityManagerInterface|MockObject */
+ /** @var EntityManagerInterface&MockObject */
private $wrapped;
protected function setUp(): void
diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
index 9106f8e29a4..84c3a16bcbc 100644
--- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
+++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
@@ -7,7 +7,6 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Configuration;
-use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
@@ -28,6 +27,7 @@
use Doctrine\Tests\Models\Company\CompanyPerson;
use Doctrine\Tests\OrmFunctionalTestCase;
use InvalidArgumentException;
+use PHPUnit\Framework\MockObject\MockObject;
use ReflectionMethod;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -221,7 +221,7 @@ public function testEntityManagerIsFilterEnabled(): void
self::assertFalse($em->getFilters()->isEnabled('foo_filter'));
}
- protected function configureFilters($em): void
+ private function configureFilters(EntityManagerInterface $em): void
{
// Add filters to the configuration of the EM
$config = $em->getConfiguration();
@@ -229,23 +229,30 @@ protected function configureFilters($em): void
$config->addFilter('soft_delete', '\Doctrine\Tests\ORM\Functional\MySoftDeleteFilter');
}
- protected function getMockConnection(): Connection
+ /**
+ * @return Connection&MockObject
+ */
+ private function getMockConnection(): Connection
{
- // Setup connection mock
return $this->createMock(Connection::class);
}
- protected function getMockEntityManager(): EntityManagerInterface
+ /**
+ * @return EntityManagerInterface&MockObject
+ */
+ private function getMockEntityManager(): EntityManagerInterface
{
- // Setup entity manager mock
- return $this->createMock(EntityManager::class);
+ return $this->createMock(EntityManagerInterface::class);
}
- protected function addMockFilterCollection(EntityManagerInterface $em): FilterCollection
+ /**
+ * @psalm-param EntityManagerInterface&MockObject $em
+ *
+ * @return FilterCollection&MockObject
+ */
+ private function addMockFilterCollection(EntityManagerInterface $em): FilterCollection
{
- $filterCollection = $this->getMockBuilder(FilterCollection::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $filterCollection = $this->createMock(FilterCollection::class);
$em->expects(self::any())
->method('getFilters')
diff --git a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php
index 9dfb444bfcc..ebc67dc843a 100644
--- a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php
+++ b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php
@@ -22,16 +22,16 @@
*/
class AbstractHydratorTest extends OrmFunctionalTestCase
{
- /** @var EventManager|MockObject */
+ /** @var EventManager&MockObject */
private $mockEventManager;
- /** @var Result|MockObject */
+ /** @var Result&MockObject */
private $mockResult;
- /** @var ResultSetMapping|MockObject */
+ /** @var ResultSetMapping&MockObject */
private $mockResultMapping;
- /** @var AbstractHydrator */
+ /** @var AbstractHydrator&MockObject */
private $hydrator;
protected function setUp(): void
@@ -42,7 +42,7 @@ protected function setUp(): void
$mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class);
$this->mockEventManager = $this->createMock(EventManager::class);
$this->mockResult = $this->createMock(Result::class);
- $this->mockResultMapping = $this->getMockBuilder(ResultSetMapping::class);
+ $this->mockResultMapping = $this->createMock(ResultSetMapping::class);
$mockEntityManagerInterface
->expects(self::any())
diff --git a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php
index e59122e422e..e3b0b2e1aca 100644
--- a/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php
+++ b/tests/Doctrine/Tests/ORM/Internal/HydrationCompleteHandlerTest.php
@@ -24,10 +24,10 @@
*/
class HydrationCompleteHandlerTest extends TestCase
{
- /** @var ListenersInvoker|MockObject */
+ /** @var ListenersInvoker&MockObject */
private $listenersInvoker;
- /** @var EntityManagerInterface|MockObject */
+ /** @var EntityManagerInterface&MockObject */
private $entityManager;
/** @var HydrationCompleteHandler */
diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php
index 7369b5165c8..3aff55b38b1 100644
--- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php
+++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php
@@ -17,7 +17,7 @@
*/
class LazyCriteriaCollectionTest extends TestCase
{
- /** @var EntityPersister|MockObject */
+ /** @var EntityPersister&MockObject */
private $persister;
/** @var Criteria */
diff --git a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php
index 649433e129e..1232b1a2b0e 100644
--- a/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php
+++ b/tests/Doctrine/Tests/ORM/Repository/DefaultRepositoryFactoryTest.php
@@ -4,6 +4,7 @@
namespace Doctrine\Tests\ORM\Repository;
+use Closure;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
@@ -22,10 +23,10 @@
*/
class DefaultRepositoryFactoryTest extends TestCase
{
- /** @var EntityManagerInterface|MockObject */
+ /** @var EntityManagerInterface&MockObject */
private $entityManager;
- /** @var Configuration|MockObject */
+ /** @var Configuration&MockObject */
private $configuration;
/** @var DefaultRepositoryFactory */
@@ -48,7 +49,7 @@ public function testCreatesRepositoryFromDefaultRepositoryClass(): void
$this->entityManager
->expects(self::any())
->method('getClassMetadata')
- ->will(self::returnCallback([$this, 'buildClassMetadata']));
+ ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])));
self::assertInstanceOf(
DDC869PaymentRepository::class,
@@ -61,7 +62,7 @@ public function testCreatedRepositoriesAreCached(): void
$this->entityManager
->expects(self::any())
->method('getClassMetadata')
- ->will(self::returnCallback([$this, 'buildClassMetadata']));
+ ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])));
self::assertSame(
$this->repositoryFactory->getRepository($this->entityManager, self::class),
@@ -92,11 +93,11 @@ public function testCachesDistinctRepositoriesPerDistinctEntityManager(): void
$em1->expects(self::any())
->method('getClassMetadata')
- ->will(self::returnCallback([$this, 'buildClassMetadata']));
+ ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])));
$em2->expects(self::any())
->method('getClassMetadata')
- ->will(self::returnCallback([$this, 'buildClassMetadata']));
+ ->will(self::returnCallback(Closure::fromCallable([$this, 'buildClassMetadata'])));
$repo1 = $this->repositoryFactory->getRepository($em1, self::class);
$repo2 = $this->repositoryFactory->getRepository($em2, self::class);
@@ -108,15 +109,11 @@ public function testCachesDistinctRepositoriesPerDistinctEntityManager(): void
}
/**
- * @return MockObject|ClassMetadata
- *
- * @private
+ * @return ClassMetadata&MockObject
*/
- public function buildClassMetadata(string $className)
+ private function buildClassMetadata(string $className): ClassMetadata
{
$metadata = $this->createMock(ClassMetadata::class);
- assert($metadata instanceof ClassMetadata || $metadata instanceof MockObject);
-
$metadata->expects(self::any())->method('getName')->will(self::returnValue($className));
$metadata->customRepositoryClassName = null;
@@ -125,7 +122,7 @@ public function buildClassMetadata(string $className)
}
/**
- * @return EntityManagerInterface|MockObject
+ * @return EntityManagerInterface&MockObject
*/
private function createEntityManager(): EntityManagerInterface
{
diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php
index 2ce23abdd02..db82f25c945 100644
--- a/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php
+++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/PaginatorTest.php
@@ -13,14 +13,15 @@
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock;
use Doctrine\Tests\OrmTestCase;
+use PHPUnit\Framework\MockObject\MockObject;
class PaginatorTest extends OrmTestCase
{
- /** @var Connection */
+ /** @var Connection&MockObject */
private $connection;
- /** @var EntityManagerInterface */
+ /** @var EntityManagerInterface&MockObject */
private $em;
- /** @var AbstractHydrator */
+ /** @var AbstractHydrator&MockObject */
private $hydrator;
protected function setUp(): void
diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
index 31e616e0d93..0d19261fcf9 100644
--- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
+++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
@@ -60,7 +60,7 @@ class UnitOfWorkTest extends OrmTestCase
/**
* Provides a sequence mock to the UnitOfWork
*
- * @var ConnectionMock
+ * @var ConnectionMock&MockObject
*/
private $_connectionMock;
@@ -71,7 +71,7 @@ class UnitOfWorkTest extends OrmTestCase
*/
private $_emMock;
- /** @var EventManager|MockObject */
+ /** @var EventManager&MockObject */
private $eventManager;
protected function setUp(): void