From a457e72c6d6430a793ad22678b4ed4c9d45a8058 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 17 Nov 2021 11:59:30 +0100 Subject: [PATCH] Add some generics to tests --- phpstan-baseline.neon | 13 +- .../Tests/Events/LifecycleListenersTest.php | 3 + .../Tests/Functional/AtomicSetTest.php | 2 +- .../Functional/CustomCollectionsTest.php | 25 ++- .../Functional/DocumentPersisterTest.php | 2 +- .../Functional/OrphanRemovalEmbedTest.php | 6 + .../Tests/Functional/OrphanRemovalTest.php | 6 + .../Tests/Functional/RepositoriesTest.php | 2 +- .../Tests/Functional/Ticket/GH1232Test.php | 3 + .../Tests/Functional/Ticket/GH1572Test.php | 6 + .../Tests/Functional/Ticket/GH597Test.php | 6 + .../Tests/Functional/Ticket/MODM29Test.php | 3 + .../Tests/Functional/Ticket/MODM81Test.php | 3 + .../Mapping/AbstractMappingDriverTest.php | 147 ++++++++++++------ .../Tests/Mapping/ClassMetadataTest.php | 5 + .../fixtures/PrimedCollectionDocument.php | 6 + .../PersistentCollection/CollNoReturnType.php | 5 + .../CollWithNullableReturnType.php | 5 + .../CollWithPHP80Types.php | 9 ++ .../CollWithReturnType.php | 5 + .../Tests/PersistentCollectionTest.php | 2 +- .../DefaultGridFSRepositoryTest.php | 8 +- .../ODM/MongoDB/Tests/SchemaManagerTest.php | 3 + .../ODM/MongoDB/Tests/UnitOfWorkTest.php | 3 + tests/Documents/Album.php | 3 + tests/Documents/BaseCategoryRepository.php | 3 + tests/Documents/CmsUser.php | 6 + tests/Documents/CommentRepository.php | 3 + .../Documents/CustomRepository/Repository.php | 3 + tests/Documents/Developer.php | 3 + tests/Documents/Phonebook.php | 3 + tests/Documents/ProfileNotify.php | 5 +- tests/Documents/UserNameRepository.php | 4 + tests/Documents/UserRepository.php | 3 + tests/Documents74/TypedDocument.php | 9 +- 35 files changed, 259 insertions(+), 64 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 54ba09384d..53949a6521 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -209,12 +209,6 @@ parameters: count: 1 path: lib/Doctrine/ODM/MongoDB/Types/DateImmutableType.php - # See https://github.com/phpstan/phpstan/issues/5512 - - - message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Functional\\\\My.*Collection\\:\\:.*\\(\\) should return Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Functional\\\\My.*Collection but returns Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\<\\(int\\|string\\), mixed\\>\\.$#" - count: 3 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php - # These classes are not final - message: "#^Unsafe call to private method Doctrine\\\\ODM\\\\MongoDB\\\\Query\\\\Expr\\:\\:convertExpression\\(\\) through static::\\.$#" @@ -253,6 +247,12 @@ parameters: count: 1 path: tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php + # Collection elements cannot be covariant, see https://github.com/doctrine/collections/pull/220 + - + message: "#^Parameter \\#2 \\$projects of class Documents\\\\Developer constructor expects Doctrine\\\\Common\\\\Collections\\\\Collection\\\\|null, Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\ given\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php + # See https://github.com/phpstan/phpstan/issues/5860 - message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\UnitOfWork\\:\\:getOrCreateDocument\\(\\) should return T of object but returns \\(Doctrine\\\\Persistence\\\\NotifyPropertyChanged&ProxyManager\\\\Proxy\\\\GhostObjectInterface&T of object\\)\\|\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface&T of object\\)\\|T of object\\.$#" @@ -284,6 +284,7 @@ parameters: message: "#^Unable to resolve the template type T in call to method Doctrine\\\\ODM\\\\MongoDB\\\\DocumentManager\\:\\:getClassMetadata\\(\\)$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php + - message: "#Property .+ is never written, only read.#" path: tests diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php index 1342563c68..3490cddd10 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleListenersTest.php @@ -250,6 +250,9 @@ public function __construct(TestCase $phpunit) $this->phpunit = $phpunit; } + /** + * @param PostCollectionLoadEventArgs $e + */ public function postCollectionLoad(PostCollectionLoadEventArgs $e): void { switch ($this->at++) { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php index 46c8b87427..ed01055b39 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php @@ -90,7 +90,7 @@ public function testAtomicUpsert(): void } /** - * @param array|ArrayCollection|null $clearWith + * @param mixed[]|ArrayCollection|null $clearWith * * @dataProvider provideAtomicCollectionUnset */ diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php index b45c3db6d8..99c6b3d273 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php @@ -205,7 +205,7 @@ class DocumentWithCustomCollection * targetDocument=EmbeddedDocumentInCustomCollection::class * ) * - * @var MyEmbedsCollection + * @var MyEmbedsCollection */ public $coll; @@ -225,7 +225,7 @@ class DocumentWithCustomCollection * targetDocument=DocumentWithCustomCollection::class * ) * - * @var MyDocumentsCollection + * @var MyDocumentsCollection */ public $refMany; @@ -236,7 +236,7 @@ class DocumentWithCustomCollection * targetDocument=DocumentWithCustomCollection::class * ) * - * @var MyDocumentsCollection + * @var MyDocumentsCollection */ public $inverseRefMany; @@ -275,8 +275,16 @@ public function __construct(string $name, bool $enabled) } } +/** + * @template TKey of array-key + * @template TElement + * @template-extends ArrayCollection + */ class MyEmbedsCollection extends ArrayCollection { + /** + * @return MyEmbedsCollection + */ public function getByName(string $name): MyEmbedsCollection { return $this->filter(static function ($item) use ($name) { @@ -284,6 +292,9 @@ public function getByName(string $name): MyEmbedsCollection }); } + /** + * @return MyEmbedsCollection + */ public function getEnabled(): MyEmbedsCollection { return $this->filter(static function ($item) { @@ -303,8 +314,16 @@ public function nothingReally(): void } } +/** + * @template TKey of array-key + * @template TElement + * @template-extends ArrayCollection + */ class MyDocumentsCollection extends ArrayCollection { + /** + * @return MyDocumentsCollection + */ public function havingEmbeds(): MyDocumentsCollection { return $this->filter(static function ($item) { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php index 59ba672358..8859cbdb5d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php @@ -32,7 +32,7 @@ class DocumentPersisterTest extends BaseTest /** @var class-string */ private $class; - /** @var DocumentPersister */ + /** @var DocumentPersister */ private $documentPersister; public function setUp(): void diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php index 2788bfd9ce..bb5bea878f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php @@ -141,6 +141,9 @@ public function testClearAndAddEmbedMany(): void $this->assertNotNull($this->getAddressRepository()->find($address3->id), 'Should have added address 3'); } + /** + * @return DocumentRepository + */ private function getUserRepository(): DocumentRepository { $repository = $this->dm->getRepository(OrphanRemovalCascadeUser::class); @@ -150,6 +153,9 @@ private function getUserRepository(): DocumentRepository return $repository; } + /** + * @return DocumentRepository + */ private function getAddressRepository(): DocumentRepository { $repository = $this->dm->getRepository(OrphanRemovalCascadeAddress::class); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php index e5832cfd2b..6abcabafcc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php @@ -282,6 +282,9 @@ public function testOrphanRemovalReferenceManyOnRemoveWithoutCascade(): void $this->assertNull($this->getProfileRepository()->find($profile2->id), 'Profile 2 should have been removed'); } + /** + * @return DocumentRepository + */ private function getUserRepository(): DocumentRepository { $repository = $this->dm->getRepository(OrphanRemovalUser::class); @@ -291,6 +294,9 @@ private function getUserRepository(): DocumentRepository return $repository; } + /** + * @return DocumentRepository + */ private function getProfileRepository(): DocumentRepository { $repository = $this->dm->getRepository(OrphanRemovalProfile::class); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php index c8456bea24..2adafd1bc4 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/RepositoriesTest.php @@ -14,7 +14,7 @@ class RepositoriesTest extends BaseTest /** @var User */ private $user; - /** @var DocumentRepository */ + /** @var DocumentRepository */ private $repository; public function setUp(): void diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php index 4513515d5e..6c0fa9596c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php @@ -87,6 +87,9 @@ class GH1232Comment public $post; } +/** + * @template-extends DocumentRepository + */ class GH1232CommentRepository extends DocumentRepository { /** diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php index 9d1c6dc03a..4b654de91c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php @@ -99,8 +99,14 @@ public function __construct(GH1572Blog $blog) } } +/** + * @template-extends DocumentRepository + */ class GH1572PostRepository extends DocumentRepository { + /** + * @return Iterator + */ public function getPostsForBlog(GH1572Blog $blog): Iterator { return $this->createQueryBuilder() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php index 97005f4c3e..a234a5090a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php @@ -155,11 +155,17 @@ public function getId(): ?string return $this->id; } + /** + * @return Collection + */ public function getComments(): Collection { return $this->comments; } + /** + * @return Collection + */ public function getReferenceMany(): Collection { return $this->referenceMany; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM29Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM29Test.php index 946a5a89b7..5acd2b2720 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM29Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM29Test.php @@ -68,6 +68,9 @@ class MODM29Doc */ protected $collection; + /** + * @param Collection $c + */ public function __construct(Collection $c) { $this->set($c); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php index 6d43501a69..9fc815ac1b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php @@ -99,6 +99,9 @@ public function setName(string $name): void $this->name = $name; } + /** + * @return Collection + */ public function getEmbeddedDocuments(): Collection { return $this->embeddedDocuments; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php index f8d2cfbde6..9e7fe3698d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php @@ -33,6 +33,8 @@ protected function createMetadataDriverImpl(): MappingDriver } /** + * @return ClassMetadata + * * @doesNotPerformAssertions */ public function testLoadMapping(): ClassMetadata @@ -41,11 +43,13 @@ public function testLoadMapping(): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testLoadMapping */ - public function testDocumentCollectionNameAndInheritance($class): ClassMetadata + public function testDocumentCollectionNameAndInheritance(ClassMetadata $class): ClassMetadata { $this->assertEquals('cms_users', $class->getCollection()); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType); @@ -54,11 +58,13 @@ public function testDocumentCollectionNameAndInheritance($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testLoadMapping */ - public function testDocumentMarkedAsReadOnly($class): ClassMetadata + public function testDocumentMarkedAsReadOnly(ClassMetadata $class): ClassMetadata { $this->assertTrue($class->isReadOnly); @@ -66,11 +72,13 @@ public function testDocumentMarkedAsReadOnly($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testDocumentCollectionNameAndInheritance */ - public function testDocumentLevelReadPreference($class): ClassMetadata + public function testDocumentLevelReadPreference(ClassMetadata $class): ClassMetadata { $this->assertEquals('primaryPreferred', $class->readPreference); $this->assertEquals([ @@ -83,11 +91,13 @@ public function testDocumentLevelReadPreference($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testDocumentCollectionNameAndInheritance */ - public function testDocumentLevelWriteConcern($class): ClassMetadata + public function testDocumentLevelWriteConcern(ClassMetadata $class): ClassMetadata { $this->assertEquals(1, $class->getWriteConcern()); @@ -95,11 +105,13 @@ public function testDocumentLevelWriteConcern($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testDocumentLevelWriteConcern */ - public function testFieldMappings($class): ClassMetadata + public function testFieldMappings(ClassMetadata $class): ClassMetadata { $this->assertCount(14, $class->fieldMappings); $this->assertTrue(isset($class->fieldMappings['identifier'])); @@ -113,11 +125,11 @@ public function testFieldMappings($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class * * @depends testDocumentCollectionNameAndInheritance */ - public function testAssociationMappings($class): void + public function testAssociationMappings(ClassMetadata $class): void { $this->assertCount(6, $class->associationMappings); $this->assertTrue(isset($class->associationMappings['address'])); @@ -129,11 +141,11 @@ public function testAssociationMappings($class): void } /** - * @param ClassMetadata $class + * @param ClassMetadata $class * * @depends testDocumentCollectionNameAndInheritance */ - public function testGetAssociationTargetClass($class): void + public function testGetAssociationTargetClass(ClassMetadata $class): void { $this->assertEquals(Address::class, $class->getAssociationTargetClass('address')); $this->assertEquals(Group::class, $class->getAssociationTargetClass('groups')); @@ -144,22 +156,24 @@ public function testGetAssociationTargetClass($class): void } /** - * @param ClassMetadata $class + * @param ClassMetadata $class * * @depends testDocumentCollectionNameAndInheritance */ - public function testGetAssociationTargetClassThrowsExceptionWhenEmpty($class): void + public function testGetAssociationTargetClassThrowsExceptionWhenEmpty(ClassMetadata $class): void { $this->expectException(InvalidArgumentException::class); $class->getAssociationTargetClass('invalid_association'); } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testDocumentCollectionNameAndInheritance */ - public function testStringFieldMappings($class): ClassMetadata + public function testStringFieldMappings(ClassMetadata $class): ClassMetadata { $this->assertEquals('string', $class->fieldMappings['name']['type']); @@ -167,11 +181,13 @@ public function testStringFieldMappings($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testFieldMappings */ - public function testIdentifier($class): ClassMetadata + public function testIdentifier(ClassMetadata $class): ClassMetadata { $this->assertEquals('identifier', $class->identifier); @@ -179,11 +195,13 @@ public function testIdentifier($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testFieldMappings */ - public function testVersionFieldMappings($class): ClassMetadata + public function testVersionFieldMappings(ClassMetadata $class): ClassMetadata { $this->assertEquals('int', $class->fieldMappings['version']['type']); $this->assertNotEmpty($class->fieldMappings['version']['version']); @@ -192,11 +210,13 @@ public function testVersionFieldMappings($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testFieldMappings */ - public function testLockFieldMappings($class): ClassMetadata + public function testLockFieldMappings(ClassMetadata $class): ClassMetadata { $this->assertEquals('int', $class->fieldMappings['lock']['type']); $this->assertNotEmpty($class->fieldMappings['lock']['lock']); @@ -205,11 +225,13 @@ public function testLockFieldMappings($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testIdentifier */ - public function testAssocations($class): ClassMetadata + public function testAssocations(ClassMetadata $class): ClassMetadata { $this->assertCount(14, $class->fieldMappings); @@ -217,11 +239,13 @@ public function testAssocations($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testAssocations */ - public function testOwningOneToOneAssocation($class): ClassMetadata + public function testOwningOneToOneAssociation(ClassMetadata $class): ClassMetadata { $this->assertTrue(isset($class->fieldMappings['address'])); $this->assertIsArray($class->fieldMappings['address']); @@ -236,11 +260,13 @@ public function testOwningOneToOneAssocation($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * - * @depends testOwningOneToOneAssocation + * @depends testOwningOneToOneAssociation */ - public function testLifecycleCallbacks($class): ClassMetadata + public function testLifecycleCallbacks(ClassMetadata $class): ClassMetadata { $expectedLifecycleCallbacks = [ 'prePersist' => ['doStuffOnPrePersist', 'doOtherStuffOnPrePersistToo'], @@ -253,11 +279,13 @@ public function testLifecycleCallbacks($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testLifecycleCallbacks */ - public function testCustomFieldName($class): ClassMetadata + public function testCustomFieldName(ClassMetadata $class): ClassMetadata { $this->assertEquals('name', $class->fieldMappings['name']['fieldName']); $this->assertEquals('username', $class->fieldMappings['name']['name']); @@ -266,11 +294,13 @@ public function testCustomFieldName($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testCustomFieldName */ - public function testCustomReferenceFieldName($class): ClassMetadata + public function testCustomReferenceFieldName(ClassMetadata $class): ClassMetadata { $this->assertEquals('morePhoneNumbers', $class->fieldMappings['morePhoneNumbers']['fieldName']); $this->assertEquals('more_phone_numbers', $class->fieldMappings['morePhoneNumbers']['name']); @@ -279,11 +309,13 @@ public function testCustomReferenceFieldName($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testCustomReferenceFieldName */ - public function testCustomEmbedFieldName($class): ClassMetadata + public function testCustomEmbedFieldName(ClassMetadata $class): ClassMetadata { $this->assertEquals('embeddedPhonenumber', $class->fieldMappings['embeddedPhonenumber']['fieldName']); $this->assertEquals('embedded_phone_number', $class->fieldMappings['embeddedPhonenumber']['name']); @@ -292,11 +324,13 @@ public function testCustomEmbedFieldName($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testCustomEmbedFieldName */ - public function testDiscriminator($class): ClassMetadata + public function testDiscriminator(ClassMetadata $class): ClassMetadata { $this->assertEquals('discr', $class->discriminatorField); $this->assertEquals(['default' => AbstractMappingDriverUser::class], $class->discriminatorMap); @@ -306,11 +340,13 @@ public function testDiscriminator($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testDiscriminator */ - public function testEmbedDiscriminator($class): ClassMetadata + public function testEmbedDiscriminator(ClassMetadata $class): ClassMetadata { $this->assertTrue(isset($class->fieldMappings['otherPhonenumbers']['discriminatorField'])); $this->assertTrue(isset($class->fieldMappings['otherPhonenumbers']['discriminatorMap'])); @@ -326,11 +362,13 @@ public function testEmbedDiscriminator($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testEmbedDiscriminator */ - public function testReferenceDiscriminator($class): ClassMetadata + public function testReferenceDiscriminator(ClassMetadata $class): ClassMetadata { $this->assertTrue(isset($class->fieldMappings['phonenumbers']['discriminatorField'])); $this->assertTrue(isset($class->fieldMappings['phonenumbers']['discriminatorMap'])); @@ -346,11 +384,13 @@ public function testReferenceDiscriminator($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class + * + * @return ClassMetadata * * @depends testCustomFieldName */ - public function testIndexes($class): ClassMetadata + public function testIndexes(ClassMetadata $class): ClassMetadata { $indexes = $class->indexes; @@ -394,11 +434,11 @@ public function testIndexes($class): ClassMetadata } /** - * @param ClassMetadata $class + * @param ClassMetadata $class * * @depends testIndexes */ - public function testShardKey($class): void + public function testShardKey(ClassMetadata $class): void { $shardKey = $class->getShardKey(); @@ -744,6 +784,9 @@ public function doStuffOnPostPersist(): void { } + /** + * @param ClassMetadata $metadata + */ public static function loadMetadata(ClassMetadata $metadata): void { $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_NONE); @@ -837,6 +880,9 @@ public static function loadMetadata(ClassMetadata $metadata): void } } +/** + * @template-extends ArrayCollection + */ class PhonenumberCollection extends ArrayCollection { } @@ -948,6 +994,9 @@ class AbstractMappingDriverFileWithCustomRepository public $id; } +/** + * @template-extends DefaultGridFSRepository + */ class AbstractMappingDriverGridFSRepository extends DefaultGridFSRepository { } @@ -1154,6 +1203,10 @@ class AbstractMappingDriverView public $name; } +/** + * @template-extends DocumentRepository + * @template-implements ViewRepository + */ class AbstractMappingDriverViewRepository extends DocumentRepository implements ViewRepository { public function createViewAggregation(Builder $builder): void diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php index 9091494f94..023a86a248 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php @@ -262,6 +262,8 @@ public function testMapNotExistingFieldThrowsException(): void } /** + * @param ClassMetadata $cm + * * @dataProvider dataProviderMetadataClasses */ public function testEmbeddedDocumentWithDiscriminator(ClassMetadata $cm): void @@ -854,6 +856,9 @@ public function testDefaultValueForValidationLevel(): void } } +/** + * @template-extends DocumentRepository + */ class TestCustomRepositoryClass extends DocumentRepository { } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/PrimedCollectionDocument.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/PrimedCollectionDocument.php index d052a7e4bf..2384045034 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/PrimedCollectionDocument.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/PrimedCollectionDocument.php @@ -29,11 +29,17 @@ public function getId(): ?string return $this->id; } + /** + * @return Collection + */ public function getInverseMappedBy(): Collection { return $this->inverseMappedBy; } + /** + * @return Collection + */ public function getReferences(): Collection { return $this->references; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollNoReturnType.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollNoReturnType.php index f74ec815b1..e8a60e4b7b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollNoReturnType.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollNoReturnType.php @@ -6,6 +6,11 @@ use Doctrine\Common\Collections\ArrayCollection; +/** + * @template TKey of array-key + * @template TElement + * @template-extends ArrayCollection + */ class CollNoReturnType extends ArrayCollection { } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithNullableReturnType.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithNullableReturnType.php index 57cf9e4728..b87d503f0f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithNullableReturnType.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithNullableReturnType.php @@ -9,6 +9,11 @@ use function rand; +/** + * @template TKey of array-key + * @template TElement + * @template-extends ArrayCollection + */ class CollWithNullableReturnType extends ArrayCollection { public function maybeGetDate(): ?DateTime diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP80Types.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP80Types.php index 394e7b9b3f..9e2a6325a5 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP80Types.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP80Types.php @@ -7,6 +7,11 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +/** + * @template TKey of array-key + * @template TElement + * @template-extends ArrayCollection + */ class CollWithPHP80Types extends ArrayCollection { public function mixed(mixed $param) : mixed @@ -14,6 +19,10 @@ public function mixed(mixed $param) : mixed return $param; } + /** + * @param Collection|ArrayCollection $param + * @return Collection|ArrayCollection + */ public function union(Collection|ArrayCollection $param) : Collection|ArrayCollection { return $param; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithReturnType.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithReturnType.php index 116faecbd9..bfb9049887 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithReturnType.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithReturnType.php @@ -7,6 +7,11 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; +/** + * @template TKey of array-key + * @template TElement + * @template-extends ArrayCollection + */ class CollWithReturnType extends ArrayCollection { public function getDate(): DateTime diff --git a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php index 1b8641ece5..892c5e8fb0 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php @@ -334,7 +334,7 @@ public function testIsEmptyUsesCountWhenCollectionIsNotInitialized(): void } /** - * @return Collection&MockObject + * @return Collection&MockObject */ private function getMockCollection() { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php index 426754c32e..a7bccc8c6b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Doctrine\ODM\MongoDB\Tests\Repos; +namespace Doctrine\ODM\MongoDB\Tests\Repository; use DateTime; use Doctrine\ODM\MongoDB\Mapping\MappingException; @@ -256,7 +256,11 @@ public function testUploadFileWithoutChunkSize(): void } /** - * @param class-string $className + * @param class-string $className + * + * @return GridFSRepository + * + * @template T of object */ private function getRepository(string $className = File::class): GridFSRepository { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php index dbf813dd10..4fc0e3f8cb 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php @@ -1105,6 +1105,9 @@ public function dataIsMongoTextIndexEquivalentToDocumentIndex(): array ]; } + /** + * @param ClassMetadata $cm + */ private function getDatabaseName(ClassMetadata $cm): string { return $cm->getDatabase() ?: $this->dm->getConfiguration()->getDefaultDB() ?: 'doctrine'; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php index 930c035235..6fe46b4349 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php @@ -625,6 +625,9 @@ public function setData(string $data): void $this->data = $data; } + /** + * @return Collection + */ public function getItems(): Collection { return $this->items; diff --git a/tests/Documents/Album.php b/tests/Documents/Album.php index fb62b01316..be1f3e45fa 100644 --- a/tests/Documents/Album.php +++ b/tests/Documents/Album.php @@ -58,6 +58,9 @@ public function addSong(Song $song): void $this->songs[] = $song; } + /** + * @return Collection + */ public function getSongs(): Collection { return $this->songs; diff --git a/tests/Documents/BaseCategoryRepository.php b/tests/Documents/BaseCategoryRepository.php index 88d106011a..3761e06db8 100644 --- a/tests/Documents/BaseCategoryRepository.php +++ b/tests/Documents/BaseCategoryRepository.php @@ -6,6 +6,9 @@ use Doctrine\ODM\MongoDB\Repository\DocumentRepository; +/** + * @template-extends DocumentRepository + */ class BaseCategoryRepository extends DocumentRepository { } diff --git a/tests/Documents/CmsUser.php b/tests/Documents/CmsUser.php index 9872504056..a98a83e605 100644 --- a/tests/Documents/CmsUser.php +++ b/tests/Documents/CmsUser.php @@ -110,6 +110,9 @@ public function addPhonenumber(CmsPhonenumber $phone): void $phone->setUser($this); } + /** + * @return Collection + */ public function getPhonenumbers(): Collection { return $this->phonenumbers; @@ -127,6 +130,9 @@ public function addGroup(CmsGroup $group): void $group->addUser($this); } + /** + * @return Collection + */ public function getGroups(): Collection { return $this->groups; diff --git a/tests/Documents/CommentRepository.php b/tests/Documents/CommentRepository.php index 43ecb96fc5..2e9678bd0f 100644 --- a/tests/Documents/CommentRepository.php +++ b/tests/Documents/CommentRepository.php @@ -24,6 +24,9 @@ public function findOneComment() ->current(); } + /** + * @return Iterator + */ public function findManyComments(): Iterator { return $this->getDocumentPersister()->loadAll(); diff --git a/tests/Documents/CustomRepository/Repository.php b/tests/Documents/CustomRepository/Repository.php index 8575ad6a76..27d0173db0 100644 --- a/tests/Documents/CustomRepository/Repository.php +++ b/tests/Documents/CustomRepository/Repository.php @@ -6,6 +6,9 @@ use Doctrine\ODM\MongoDB\Repository\DocumentRepository; +/** + * @template-extends DocumentRepository + */ class Repository extends DocumentRepository { } diff --git a/tests/Documents/Developer.php b/tests/Documents/Developer.php index 70d2573620..bc5aa51caf 100644 --- a/tests/Documents/Developer.php +++ b/tests/Documents/Developer.php @@ -34,6 +34,9 @@ class Developer */ private $projects; + /** + * @param Collection|null $projects + */ public function __construct(string $name, ?Collection $projects = null) { $this->name = $name; diff --git a/tests/Documents/Phonebook.php b/tests/Documents/Phonebook.php index 91b261e577..5eb627e50d 100644 --- a/tests/Documents/Phonebook.php +++ b/tests/Documents/Phonebook.php @@ -46,6 +46,9 @@ public function addPhonenumber(Phonenumber $phonenumber): void $this->phonenumbers->add($phonenumber); } + /** + * @return Collection + */ public function getPhonenumbers(): Collection { return $this->phonenumbers; diff --git a/tests/Documents/ProfileNotify.php b/tests/Documents/ProfileNotify.php index 6181ffa777..431a32dcd1 100644 --- a/tests/Documents/ProfileNotify.php +++ b/tests/Documents/ProfileNotify.php @@ -43,7 +43,7 @@ class ProfileNotify implements NotifyPropertyChanged /** * @ODM\ReferenceMany(targetDocument=File::class, cascade={"all"}, collectionClass=ProfileNotifyImagesCollection::class) * - * @var ProfileNotifyImagesCollection + * @var ProfileNotifyImagesCollection */ private $images; @@ -109,6 +109,9 @@ public function getImage(): ?File return $this->image; } + /** + * @return ProfileNotifyImagesCollection + */ public function getImages(): ProfileNotifyImagesCollection { return $this->images; diff --git a/tests/Documents/UserNameRepository.php b/tests/Documents/UserNameRepository.php index 1ed34a6e45..4882c55038 100644 --- a/tests/Documents/UserNameRepository.php +++ b/tests/Documents/UserNameRepository.php @@ -8,6 +8,10 @@ use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use Doctrine\ODM\MongoDB\Repository\ViewRepository; +/** + * @template-extends DocumentRepository + * @template-implements ViewRepository + */ class UserNameRepository extends DocumentRepository implements ViewRepository { public function createViewAggregation(Builder $builder): void diff --git a/tests/Documents/UserRepository.php b/tests/Documents/UserRepository.php index fd68d5f15d..028296da78 100644 --- a/tests/Documents/UserRepository.php +++ b/tests/Documents/UserRepository.php @@ -6,6 +6,9 @@ use Doctrine\ODM\MongoDB\Repository\DocumentRepository; +/** + * @template-extends DocumentRepository + */ class UserRepository extends DocumentRepository { } diff --git a/tests/Documents74/TypedDocument.php b/tests/Documents74/TypedDocument.php index 8dedacead0..05c3413fd1 100644 --- a/tests/Documents74/TypedDocument.php +++ b/tests/Documents74/TypedDocument.php @@ -37,7 +37,11 @@ class TypedDocument /** @ODM\ReferenceOne(targetDocument=TypedDocument::class, nullable=true) */ public ?TypedDocument $initializedNullableReferenceOne = null; - /** @ODM\EmbedMany(targetDocument=TypedEmbeddedDocument::class) */ + /** + * @ODM\EmbedMany(targetDocument=TypedEmbeddedDocument::class) + * + * @var Collection + */ private Collection $embedMany; public function __construct() @@ -45,6 +49,9 @@ public function __construct() $this->embedMany = new ArrayCollection(); } + /** + * @return Collection + */ public function getEmbedMany(): Collection { return $this->embedMany;