From 082d02bfd0d6cd396a913046eac250cdfe55abea Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 26 May 2021 14:45:48 +0200 Subject: [PATCH 1/8] Add phpstan to tests --- phpstan-baseline.neon | 12 ++++++++++++ phpstan.neon.dist | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 61de201575..aad6521117 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -31,3 +31,15 @@ parameters: count: 1 path: lib/Doctrine/ODM/MongoDB/Query/Builder.php + - + message: "#DOCTRINE_MONGODB_DATABASE not found\\.$#" + paths: + - tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php + - tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php + - tests/Doctrine/ODM/MongoDB/Tests/Id/IncrementGeneratorTest.php + - tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php + + - + message: "#DOCTRINE_MONGODB_SERVER not found\\.$#" + paths: + - tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 5121f9cb2f..73cfcac009 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,8 +4,12 @@ includes: parameters: level: 5 paths: - - %rootDir%/../../../benchmark - - %rootDir%/../../../lib + - benchmark + - lib + - tests excludes_analyse: - lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php - lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php + - tests/Hydrators/ + - tests/PersistentCollections/ + - tests/Proxies/ From 498b009843794ec0e4336182f1128884ab555c31 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 1 Jun 2021 09:43:33 +0200 Subject: [PATCH 2/8] Add phpstan-phpunit --- composer.json | 1 + phpstan.neon.dist | 1 + 2 files changed, 2 insertions(+) diff --git a/composer.json b/composer.json index 3afafe0e21..8582a034b7 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "jmikola/geojson": "^1.0", "phpbench/phpbench": "^1.0.0", "phpstan/phpstan": "^0.12.32", + "phpstan/phpstan-phpunit": "^0.12.19", "phpunit/phpunit": "^8.5 || ^9", "squizlabs/php_codesniffer": "^3.5", "symfony/cache": "^4.4 || ^5.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 73cfcac009..1499224341 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,6 @@ includes: - phpstan-baseline.neon + - vendor/phpstan/phpstan-phpunit/extension.neon parameters: level: 5 From 1580962b7e4dcf985e762d79a53d087364bcb604 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 1 Jun 2021 10:24:58 +0200 Subject: [PATCH 3/8] Remove dead code --- tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php index e3047044de..70a851d069 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php @@ -17,7 +17,6 @@ use function array_map; use function getenv; use function in_array; -use function is_callable; use function iterator_to_array; use function preg_match; use function version_compare; @@ -95,12 +94,6 @@ protected function getConfiguration() */ public static function assertArraySubset($subset, $array, bool $checkForObjectIdentity = false, string $message = ''): void { - if (is_callable([parent::class, 'assertArraySubset'])) { - parent::assertArraySubset($subset, $array, $checkForObjectIdentity, $message); - - return; - } - foreach ($subset as $key => $value) { self::assertArrayHasKey($key, $array, $message); From 25b86cd8a22bd99d0c4e8edf9214dcfee0afdba9 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 1 Jun 2021 10:26:37 +0200 Subject: [PATCH 4/8] Remove unused arguments --- tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php | 2 +- tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php | 2 +- tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php index 70a851d069..c58183a780 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php @@ -26,7 +26,7 @@ abstract class BaseTest extends TestCase { - /** @var DocumentManager */ + /** @var DocumentManager|null */ protected $dm; /** @var UnitOfWork */ protected $uow; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php index f2eaa46ea2..10aab24ea2 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php @@ -408,7 +408,7 @@ public function testAtomicSetUpdatesAllNestedCollectionsInOneQuery() // Create a book which has one chapter with one page. $chapter1 = new Chapter(); $chapter1->pages->add(new Page(1)); - $book = new Book('title'); + $book = new Book(); $book->chapters->add($chapter1); $this->dm->persist($book); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php index b02946b29c..dbc73b485a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php @@ -287,7 +287,7 @@ public function testUnsetField() ->updateOne(User::class) ->field('nullTest') ->type('null') - ->unsetField('nullTest'); + ->unsetField(); $query = $qb->getQuery(); $query->execute(); From 85c6ccbd22abd6d590b9d18fdb346e645a9028fa Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 1 Jun 2021 10:26:47 +0200 Subject: [PATCH 5/8] Add baseline --- phpstan-baseline.neon | 300 ++++++++++++++++++++++++++++++++++++++++++ phpstan.neon.dist | 1 + 2 files changed, 301 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aad6521117..3c8470a739 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -43,3 +43,303 @@ parameters: message: "#DOCTRINE_MONGODB_SERVER not found\\.$#" paths: - tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php + + - + message: "#^Parameter \\#1 \\$builder of method Doctrine\\\\ODM\\\\MongoDB\\\\Aggregation\\\\Stage\\\\Facet\\:\\:pipeline\\(\\) expects Doctrine\\\\ODM\\\\MongoDB\\\\Aggregation\\\\Builder\\|Doctrine\\\\ODM\\\\MongoDB\\\\Aggregation\\\\Stage, stdClass given\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FacetTest.php + + - + message: "#^Call to an undefined method Doctrine\\\\ODM\\\\MongoDB\\\\Aggregation\\\\Stage\\\\MatchStage\\:\\:connectFromField\\(\\)\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/GraphLookupTest.php + + - + message: "#^Class Documents\\\\Account does not have a constructor and must be instantiated without any parameters\\.$#" + count: 4 + path: tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php + + - + message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata&PHPUnit\\\\Framework\\\\MockObject\\\\MockObject and null will always evaluate to false\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Events/OnClassMetadataNotFoundEventArgsTest.php + + - + message: "#^Cannot access property \\$username on array\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomFieldNameTest.php + + - + message: "#^Offset 'userId' does not exist on array\\(\\)\\|array\\('ids' \\=\\> array\\&nonEmpty, \\?'userId' \\=\\> true\\)\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php + + - + message: "#^Cannot call method current\\(\\) on array\\|int\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php + + - + message: "#^Cannot call method next\\(\\) on array\\|int\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php + + - + message: "#^Cannot call method valid\\(\\) on array\\|int\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php + + - + message: "#^Parameter \\#1 \\$object of method Doctrine\\\\ODM\\\\MongoDB\\\\DocumentManager\\:\\:detach\\(\\) expects object, float\\|int given\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php + + - + message: "#^Parameter \\#2 \\$currency of class Documents\\\\Ecommerce\\\\Money constructor expects Documents\\\\Ecommerce\\\\Currency, int given\\.$#" + count: 6 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php + + - + message: "#^Cannot call method getCount\\(\\) on array\\|int\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/FindAndModifyTest.php + + - + message: "#^Cannot call method getUsername\\(\\) on array\\|int\\|object\\.$#" + count: 3 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/FindAndModifyTest.php + + - + message: "#^Cannot call method toArray\\(\\) on array\\|int\\|object\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php + + - + message: "#^Expression \"\\$groups\\[0\\]\" on a separate line does not do anything\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/FunctionalTest.php + + - + message: "#^Cannot call method getCount\\(\\) on array\\|int\\|object\\.$#" + count: 3 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php + + - + message: "#^Cannot call method getProfile\\(\\) on array\\|object\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/InheritanceTest.php + + - + message: "#^Access to an undefined property Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Functional\\\\AbstractVersionBase\\:\\:\\$version\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php + + - + message: "#^Cannot access property \\$blogPosts on array\\|object\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/OwningAndInverseReferencesTest.php + + - + message: "#^Cannot access property \\$name on array\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/OwningAndInverseReferencesTest.php + + - + message: "#^Cannot call method getUsername\\(\\) on array\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php + + - + message: "#^Cannot call method toArray\\(\\) on array\\|int\\|object\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php + + - + message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:setLastName\\(\\)\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php + + - + message: "#^Parameter \\#1 \\$coll of method Doctrine\\\\ODM\\\\MongoDB\\\\UnitOfWork\\:\\:isCollectionScheduledForUpdate\\(\\) expects Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\PersistentCollectionInterface, Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\ given\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php + + - + message: "#^Comparison operation \"\\<\" between \\(array\\|float\\|int\\) and 0 results in an error\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1275Test.php + + - + message: "#^Cannot call method current\\(\\) on array\\|int\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH267Test.php + + - + message: "#^Cannot assign offset '1' to Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php + + - + message: "#^Cannot unset offset '1' on Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php + + - + message: "#^Cannot access property \\$ref on array\\|object\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH520Test.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php + + - + message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:getId\\(\\)\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php + + - + message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:getId\\(\\)\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$id\\.$#" + count: 3 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$name\\.$#" + count: 3 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php + + - + message: "#^Cannot call method current\\(\\) on array\\|int\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php + + - + message: "#^Cannot call method getBody\\(\\) on array\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php + + - + message: "#^Cannot call method getTitle\\(\\) on array\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php + + - + message: "#^Cannot call method setTitle\\(\\) on array\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php + + - + message: "#^Result of \\|\\| is always true\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM92Test.php + + - + message: "#^Result of \\|\\| is always true\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM95Test.php + + - + message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:getId\\(\\)\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Functional/ViewTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$birthdate\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$embedMany\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$embedOne\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$id\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$name\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$referenceMany\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$referenceOne\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$title\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php + + - + message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\\\:\\:mapField\\(\\)\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php + + - + message: "#^Access to an undefined property Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\\\:\\:\\$namespace\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php + + - + message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:getName\\(\\)\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php + + - + message: "#^Function mongodb\\\\bson\\\\tophp invoked with 1 parameter, 2 required\\.$#" + count: 2 + path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php + + - + message: "#^Access to an undefined property Documents\\\\CmsArticle\\:\\:\\$title\\.$#" + count: 4 + path: tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php + + - + message: "#^Parameter \\#1 \\$primer of method Doctrine\\\\ODM\\\\MongoDB\\\\Query\\\\Builder\\:\\:prime\\(\\) expects bool\\|\\(callable\\(\\)\\: mixed\\), 1 given\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php + + - + message: "#^Cannot access property \\$pet on array\\|object\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php + + - + message: "#^Call to an undefined method MongoDB\\\\Collection\\:\\:expects\\(\\)\\.$#" + count: 14 + path: tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php + + - + message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\SchemaManagerTest\\:\\:writeOptions\\(\\) should return PHPUnit\\\\Framework\\\\Constraint\\\\Constraint but returns PHPUnit\\\\Framework\\\\Constraint\\\\ArraySubset\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php + + - + message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'DateTimeImmutable' and null will always evaluate to false\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Types/DateImmutableTypeTest.php + + - + message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'DateTime' and null will always evaluate to false\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Types/DateTypeTest.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1499224341..771ba56023 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,6 +11,7 @@ parameters: excludes_analyse: - lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php - lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php + - tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/User.php - tests/Hydrators/ - tests/PersistentCollections/ - tests/Proxies/ From 4db26b2a7e92d4dee71b268687dded018f29b646 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 1 Jun 2021 12:21:31 +0200 Subject: [PATCH 6/8] Add some types to phpdoc --- phpstan-baseline.neon | 30 ------------------- .../Tests/Functional/Ticket/GH593Test.php | 13 ++++++-- .../Tests/Functional/Ticket/GH602Test.php | 7 ++++- .../Tests/Functional/Ticket/GH852Test.php | 13 ++++++-- .../ODM/MongoDB/Tests/HydratorTest.php | 6 +++- tests/Documents/User.php | 8 +++-- tests/Documents/ViewReference.php | 30 ++++++++++++++++--- 7 files changed, 65 insertions(+), 42 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3c8470a739..c5c1ce8a58 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -154,11 +154,6 @@ parameters: count: 2 path: tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php - - - message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:setLastName\\(\\)\\.$#" - count: 1 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php - - message: "#^Parameter \\#1 \\$coll of method Doctrine\\\\ODM\\\\MongoDB\\\\UnitOfWork\\:\\:isCollectionScheduledForUpdate\\(\\) expects Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\PersistentCollectionInterface, Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\ given\\.$#" count: 1 @@ -194,26 +189,6 @@ parameters: count: 1 path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php - - - message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:getId\\(\\)\\.$#" - count: 2 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php - - - - message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:getId\\(\\)\\.$#" - count: 2 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php - - - - message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$id\\.$#" - count: 3 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php - - - - message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$name\\.$#" - count: 3 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php - - message: "#^Cannot call method current\\(\\) on array\\|int\\|object\\.$#" count: 1 @@ -244,11 +219,6 @@ parameters: count: 1 path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM95Test.php - - - message: "#^Call to an undefined method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/ViewTest.php - - message: "#^Access to an undefined property ProxyManager\\\\Proxy\\\\GhostObjectInterface\\:\\:\\$birthdate\\.$#" count: 1 diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php index eb2307a7e5..804e8a7f80 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\DocumentNotFoundException; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Tests\BaseTest; @@ -108,10 +109,18 @@ class GH593User /** @ODM\Field(name="d", type="bool") */ public $deleted = false; - /** @ODM\ReferenceMany(targetDocument=GH593User::class, inversedBy="followedBy", storeAs="id") */ + /** + * @ODM\ReferenceMany(targetDocument=GH593User::class, inversedBy="followedBy", storeAs="id") + * + * @var Collection + */ public $following; - /** @ODM\ReferenceMany(targetDocument=GH593User::class, mappedBy="following") */ + /** + * @ODM\ReferenceMany(targetDocument=GH593User::class, mappedBy="following") + * + * @var Collection + */ public $followedBy; public function __construct() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php index 89054d2c10..431fac06f1 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\DocumentNotFoundException; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Tests\BaseTest; @@ -110,7 +111,11 @@ class GH602User /** @ODM\Field(name="user_deleted", type="bool") */ public $deleted = false; - /** @ODM\ReferenceMany(targetDocument=GH602Thing::class, inversedBy="likedBy", storeAs="id") */ + /** + * @ODM\ReferenceMany(targetDocument=GH602Thing::class, inversedBy="likedBy", storeAs="id") + * + * @var Collection + */ public $likes; public function __construct() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php index ee9fd6142c..4a2a1d2bce 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH852Test.php @@ -6,6 +6,7 @@ use Closure; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use MongoDB\BSON\Binary; @@ -119,10 +120,18 @@ class GH852Document /** @ODM\Field(type="string") */ public $name; - /** @ODM\ReferenceOne(targetDocument=GH852Document::class, cascade="all") */ + /** + * @ODM\ReferenceOne(targetDocument=GH852Document::class, cascade="all") + * + * @var GH852Document + */ public $refOne; - /** @ODM\ReferenceMany(targetDocument=GH852Document::class, cascade="all") */ + /** + * @ODM\ReferenceMany(targetDocument=GH852Document::class, cascade="all") + * + * @var Collection + */ public $refMany; public function __construct() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php b/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php index c9d8fa39be..acfab415f9 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/HydratorTest.php @@ -193,7 +193,11 @@ class HydrationClosureUser /** @ODM\Field(type="date") */ public $birthdate; - /** @ODM\ReferenceOne(targetDocument=HydrationClosureReferenceOne::class) */ + /** + * @ODM\ReferenceOne(targetDocument=HydrationClosureReferenceOne::class) + * + * @var HydrationClosureReferenceOne + */ public $referenceOne; /** @ODM\ReferenceMany(targetDocument=HydrationClosureReferenceMany::class) */ diff --git a/tests/Documents/User.php b/tests/Documents/User.php index accbc50d01..a7de6df61c 100644 --- a/tests/Documents/User.php +++ b/tests/Documents/User.php @@ -34,7 +34,11 @@ class User extends BaseDocument /** @ODM\ReferenceOne(targetDocument=Profile::class, cascade={"all"}) */ protected $profile; - /** @ODM\ReferenceOne(targetDocument=ProfileNotify::class, cascade={"all"}) */ + /** + * @ODM\ReferenceOne(targetDocument=ProfileNotify::class, cascade={"all"}) + * + * @var ProfileNotify|null + */ protected $profileNotify; /** @ODM\EmbedMany(targetDocument=Phonenumber::class) */ @@ -200,7 +204,7 @@ public function setProfileNotify(ProfileNotify $profile) $this->profileNotify = $profile; } - public function getProfileNotify() + public function getProfileNotify(): ?ProfileNotify { return $this->profileNotify; } diff --git a/tests/Documents/ViewReference.php b/tests/Documents/ViewReference.php index 8eefe9f49b..172fdcdba8 100644 --- a/tests/Documents/ViewReference.php +++ b/tests/Documents/ViewReference.php @@ -14,16 +14,32 @@ class ViewReference /** @ODM\Id */ private $id; - /** @ODM\ReferenceOne(targetDocument=UserName::class, cascade={"persist"}) */ + /** + * @ODM\ReferenceOne(targetDocument=UserName::class, cascade={"persist"}) + * + * @var UserName + */ private $referenceOneView; - /** @ODM\ReferenceOne(targetDocument=UserName::class, mappedBy="viewReference") */ + /** + * @ODM\ReferenceOne(targetDocument=UserName::class, mappedBy="viewReference") + * + * @var UserName + */ private $referenceOneViewMappedBy; - /** @ODM\ReferenceMany(targetDocument=UserName::class, cascade={"persist"}) */ + /** + * @ODM\ReferenceMany(targetDocument=UserName::class, cascade={"persist"}) + * + * @var Collection + */ private $referenceManyView; - /** @ODM\ReferenceMany(targetDocument=UserName::class, mappedBy="viewReference") */ + /** + * @ODM\ReferenceMany(targetDocument=UserName::class, mappedBy="viewReference") + * + * @var Collection + */ private $referenceManyViewMappedBy; public function __construct(string $id) @@ -48,11 +64,17 @@ public function getReferenceOneViewMappedBy(): ?UserName return $this->referenceOneViewMappedBy; } + /** + * @return Collection + */ public function getReferenceManyView(): Collection { return $this->referenceManyView; } + /** + * @return Collection + */ public function getReferenceManyViewMappedBy(): Collection { return $this->referenceManyViewMappedBy; From 01ab0497abe7358b10599fa0d5d982d96d25085d Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 1 Jun 2021 15:14:26 +0200 Subject: [PATCH 7/8] Fix duplicate keys and types in psalm types --- .../ODM/MongoDB/Mapping/ClassMetadata.php | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index 04634c1768..f068be824a 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -62,30 +62,28 @@ * fieldName?: string, * name?: string, * strategy?: string, - * notSaved?: bool, * association?: int, * id?: bool, * collectionClass?: class-string, - * cascade?: list, + * cascade?: list|string, * embedded?: bool, * orphanRemoval?: bool, * options?: array, * nullable?: bool, * reference?: bool, * storeAs?: string, - * targetDocument?: class-string, + * targetDocument?: class-string|null, * mappedBy?: string|null, * inversedBy?: string|null, * discriminatorField?: string, * defaultDiscriminatorValue?: string, * discriminatorMap?: array, * repositoryMethod?: string|null, - * sort?: array, + * sort?: array, * limit?: int|null, * skip?: int|null, * version?: bool, * lock?: bool, - * notSaved?: bool, * inherited?: string, * declared?: class-string * } @@ -105,21 +103,21 @@ * association?: int, * id?: bool, * collectionClass?: class-string, - * cascade?: list, + * cascade?: list|string, * embedded?: bool, * orphanRemoval?: bool, * options?: array, * nullable?: bool, * reference?: bool, * storeAs?: string, - * targetDocument?: class-string, + * targetDocument?: class-string|null, * mappedBy?: string|null, * inversedBy?: string|null, * discriminatorField?: string, * defaultDiscriminatorValue?: string, * discriminatorMap?: array, * repositoryMethod?: string|null, - * sort?: array, + * sort?: array, * limit?: int|null, * skip?: int|null, * version?: bool, @@ -128,7 +126,7 @@ * inherited?: string, * declared?: class-string * } - * @psalm-type AssociationMappingField = array{ + * @psalm-type AssociationFieldMapping = array{ * type: string, * fieldName: string, * name: string, @@ -139,13 +137,12 @@ * isCascadeDetach: bool, * isOwningSide: bool, * isInverseSide: bool, - * targetDocument: class-string, + * targetDocument: class-string|null, * association: int, * strategy?: string, - * notSaved?: bool, * id?: bool, * collectionClass?: class-string, - * cascade?: list, + * cascade?: list|string, * embedded?: bool, * orphanRemoval?: bool, * options?: array, @@ -158,7 +155,7 @@ * defaultDiscriminatorValue?: string, * discriminatorMap?: array, * repositoryMethod?: string|null, - * sort?: array, + * sort?: array, * limit?: int|null, * skip?: int|null, * version?: bool, @@ -535,7 +532,7 @@ * Keys are field names and values are mapping definitions. * * @var array - * @psalm-var array + * @psalm-var array */ public $associationMappings = []; @@ -1535,7 +1532,7 @@ public function mapOneReference(array $mapping): void /** * Map a collection of document references. * - * @psalm-param FieldMapping $mapping + * @psalm-param FieldMappingConfig $mapping */ public function mapManyReference(array $mapping): void { @@ -1569,7 +1566,7 @@ public function addInheritedFieldMapping(array $fieldMapping): void * * @internal * - * @psalm-param FieldMapping $mapping + * @psalm-param AssociationFieldMapping $mapping * * @throws MappingException */ From 251a855a0aab46028464df196ce1056c68f4b779 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 1 Jun 2021 15:15:55 +0200 Subject: [PATCH 8/8] Use proper arguments in tests --- .../Tests/Mapping/ClassMetadataTest.php | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php index 706f2075da..44afdeb8f9 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php @@ -16,7 +16,9 @@ use Documents\Address; use Documents\Album; use Documents\Bars\Bar; +use Documents\CmsGroup; use Documents\CmsUser; +use Documents\CustomRepository\Repository; use Documents\SpecialUser; use Documents\User; use Documents\UserName; @@ -154,7 +156,7 @@ public function testMapManyToManyJoinTableDefaults() $cm->mapManyEmbedded( [ 'fieldName' => 'groups', - 'targetDocument' => 'CmsGroup', + 'targetDocument' => CmsGroup::class, ] ); @@ -236,7 +238,7 @@ public function testDuplicateFieldAndAssocationMapping1() { $cm = new ClassMetadata(CmsUser::class); $cm->mapField(['fieldName' => 'name', 'type' => Type::STRING]); - $cm->mapOneEmbedded(['fieldName' => 'name', 'targetDocument' => 'CmsUser']); + $cm->mapOneEmbedded(['fieldName' => 'name', 'targetDocument' => CmsUser::class]); $this->assertEquals('one', $cm->fieldMappings['name']['type']); } @@ -244,7 +246,7 @@ public function testDuplicateFieldAndAssocationMapping1() public function testDuplicateFieldAndAssocationMapping2() { $cm = new ClassMetadata(CmsUser::class); - $cm->mapOneEmbedded(['fieldName' => 'name', 'targetDocument' => 'CmsUser']); + $cm->mapOneEmbedded(['fieldName' => 'name', 'targetDocument' => CmsUser::class]); $cm->mapField(['fieldName' => 'name', 'columnName' => 'name', 'type' => 'string']); $this->assertEquals('string', $cm->fieldMappings['name']['type']); @@ -416,16 +418,16 @@ public function testSetFieldValueWithProxy() public function testSetCustomRepositoryClass() { - $cm = new ClassMetadata('Doctrine\ODM\MongoDB\Tests\Mapping\ClassMetadataTest'); + $cm = new ClassMetadata(self::class); $cm->namespace = 'Doctrine\ODM\MongoDB\Tests\Mapping'; - $cm->setCustomRepositoryClass('TestCustomRepositoryClass'); + $cm->setCustomRepositoryClass(Repository::class); - $this->assertEquals('TestCustomRepositoryClass', $cm->customRepositoryClassName); + $this->assertEquals(Repository::class, $cm->customRepositoryClassName); - $cm->setCustomRepositoryClass('Doctrine\ODM\MongoDB\Tests\Mapping\TestCustomRepositoryClass'); + $cm->setCustomRepositoryClass(TestCustomRepositoryClass::class); - $this->assertEquals('Doctrine\ODM\MongoDB\Tests\Mapping\TestCustomRepositoryClass', $cm->customRepositoryClassName); + $this->assertEquals(TestCustomRepositoryClass::class, $cm->customRepositoryClassName); } public function testEmbeddedAssociationsAlwaysCascade() @@ -636,9 +638,19 @@ public function testAddInheritedAssociationMapping() $mapping = [ 'fieldName' => 'assoc', + 'name' => 'assoc', 'reference' => true, 'type' => 'one', 'storeAs' => ClassMetadata::REFERENCE_STORE_AS_ID, + 'isCascadeRemove' => false, + 'isCascadePersist' => false, + 'isCascadeRefresh' => false, + 'isCascadeMerge' => false, + 'isCascadeDetach' => false, + 'isOwningSide' => false, + 'isInverseSide' => false, + 'targetDocument' => null, + 'association' => ClassMetadata::REFERENCE_ONE, ]; $cm->addInheritedAssociationMapping($mapping);