Skip to content

Commit

Permalink
Merge branch '2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
* 2.10.x:
  Run static analysis with language level PHP 8.1 (doctrine#9314)
  Document PHPUnit mocks with intersection types (doctrine#9318)
  • Loading branch information
derrabus committed Jan 2, 2022
2 parents 8c6fc5a + 44aa8c2 commit 2f25313
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 80 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/LazyCriteriaCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,6 +39,7 @@ public function __construct(EntityPersister $entityPersister, Criteria $criteria
*
* @return int
*/
#[ReturnTypeWillChange]
public function count()
{
if ($this->isInitialized()) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -504,6 +505,7 @@ public function offsetSet($offset, $value): void
*
* @return object|null
*/
#[ReturnTypeWillChange]
public function offsetUnset($offset)
{
return $this->remove($offset);
Expand Down
34 changes: 11 additions & 23 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion phpstan-params.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ parameters:
earlyTerminatingMethodCalls:
Doctrine\ORM\Query\Parser:
- syntaxError
phpVersion: 70100
phpVersion: 80100
14 changes: 1 addition & 13 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
phpVersion="8.1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down Expand Up @@ -102,25 +103,12 @@
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php"/>
</errorLevel>
</RedundantCondition>
<!-- Workaround for https://github.com/vimeo/psalm/issues/7026 -->
<ReservedWord>
<errorLevel type="suppress">
<directory name="lib"/>
<directory name="tests"/>
</errorLevel>
</ReservedWord>
<TypeDoesNotContainType>
<errorLevel type="suppress">
<file name="lib/Doctrine/ORM/Internal/SQLResultCasing.php"/>
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php"/>
</errorLevel>
</TypeDoesNotContainType>
<UndefinedAttributeClass>
<errorLevel type="suppress">
<!-- The class was added in PHP 8.1 -->
<referencedClass name="ReturnTypeWillChange"/>
</errorLevel>
</UndefinedAttributeClass>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\Common\Cache\ApcCache"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/Cache/CacheLoggerChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CacheLoggerChainTest extends DoctrineTestCase
/** @var CacheLoggerChain */
private $logger;

/** @var MockObject|CacheLogger */
/** @var CacheLogger&MockObject */
private $mock;

protected function setUp(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Doctrine\Tests\OrmTestCase;
use InvalidArgumentException;
use LogicException;
use PHPUnit\Framework\MockObject\MockObject;

use function assert;

Expand All @@ -39,7 +40,7 @@
*/
class DefaultCacheFactoryTest extends OrmTestCase
{
/** @var CacheFactory */
/** @var CacheFactory&MockObject */
private $factory;

/** @var EntityManager */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -70,6 +71,9 @@ protected function setUp(): void
->getMock();
}

/**
* @return Region&MockObject
*/
protected function createRegion(): Region
{
return $this->getMockBuilder(Region::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EntityManagerDecoratorTest extends TestCase
'lock',
];

/** @var EntityManagerInterface|MockObject */
/** @var EntityManagerInterface&MockObject */
private $wrapped;

protected function setUp(): void
Expand Down
29 changes: 18 additions & 11 deletions tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -221,31 +221,38 @@ 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();
$config->addFilter('locale', '\Doctrine\Tests\ORM\Functional\MyLocaleFilter');
$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')
Expand Down
10 changes: 5 additions & 5 deletions tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class LazyCriteriaCollectionTest extends TestCase
{
/** @var EntityPersister|MockObject */
/** @var EntityPersister&MockObject */
private $persister;

/** @var Criteria */
Expand Down
Loading

0 comments on commit 2f25313

Please sign in to comment.