diff --git a/benchmark/BaseBench.php b/benchmark/BaseBench.php index 90283821ca..1232fb3b54 100644 --- a/benchmark/BaseBench.php +++ b/benchmark/BaseBench.php @@ -28,15 +28,12 @@ abstract class BaseBench /** @var DocumentManager */ protected static $documentManager; - /** - * @return DocumentManager - */ - protected function getDocumentManager() + protected function getDocumentManager(): DocumentManager { return self::$documentManager; } - public function initDocumentManager() + public function initDocumentManager(): void { $config = new Configuration(); @@ -59,7 +56,7 @@ public function initDocumentManager() self::$documentManager = DocumentManager::create($client, $config); } - public function clearDatabase() + public function clearDatabase(): void { // Check if the database exists. Calling listCollections on a non-existing // database in a sharded setup will cause an invalid command cursor to be @@ -85,7 +82,7 @@ public function clearDatabase() } } - protected static function createMetadataDriverImpl() + protected static function createMetadataDriverImpl(): AnnotationDriver { return AnnotationDriver::create(__DIR__ . '/../tests/Documents'); } diff --git a/benchmark/Document/LoadDocumentBench.php b/benchmark/Document/LoadDocumentBench.php index f36ae007de..88bcd4edd5 100644 --- a/benchmark/Document/LoadDocumentBench.php +++ b/benchmark/Document/LoadDocumentBench.php @@ -25,7 +25,7 @@ final class LoadDocumentBench extends BaseBench /** @var ObjectId */ private static $userId; - public function init() + public function init(): void { self::$userId = new ObjectId(); @@ -58,7 +58,7 @@ public function init() /** * @Warmup(2) */ - public function benchLoadDocument() + public function benchLoadDocument(): void { $this->loadDocument(); } @@ -66,7 +66,7 @@ public function benchLoadDocument() /** * @Warmup(2) */ - public function benchLoadEmbedOne() + public function benchLoadEmbedOne(): void { $this->loadDocument()->getAddress()->getCity(); } @@ -74,7 +74,7 @@ public function benchLoadEmbedOne() /** * @Warmup(2) */ - public function benchLoadEmbedMany() + public function benchLoadEmbedMany(): void { $this->loadDocument()->getPhonenumbers()->forAll(static function (int $key, Phonenumber $element) { return $element->getPhoneNumber() !== null; @@ -94,8 +94,8 @@ public function benchLoadReferenceOne() */ public function benchLoadReferenceMany() { - $this->loadDocument()->getGroups()->forAll(static function ($key, Group $group) { - return $group->getName(); + $this->loadDocument()->getGroups()->forAll(static function (int $key, Group $group) { + return $group->getName() !== null; }); } diff --git a/lib/Doctrine/ODM/MongoDB/DocumentManager.php b/lib/Doctrine/ODM/MongoDB/DocumentManager.php index f56cc092d1..a335b6fae5 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentManager.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentManager.php @@ -316,6 +316,8 @@ public function getClassMetadata($className): ClassMetadata /** * Returns the MongoDB instance for a class. + * + * @psalm-param class-string $className */ public function getDocumentDatabase(string $className): Database { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 28f247ed9d..1543cd4ce7 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -33,7 +33,6 @@ - @@ -67,6 +66,10 @@ */tests/* + + */lib/* + + */tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/Coll* diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 94229f8114..0385b292e3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -59,11 +59,6 @@ parameters: 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 @@ -229,3 +224,9 @@ parameters: message: "#^Unreachable statement \\- code above always terminates\\.$#" 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 diff --git a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php index 3834aad803..eea0333167 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php @@ -104,10 +104,7 @@ public static function assertArraySubset($subset, $array, bool $checkForObjectId } } - /** - * @return MappingDriver - */ - protected function createMetadataDriverImpl() + protected function createMetadataDriverImpl(): MappingDriver { return AnnotationDriver::create(__DIR__ . '/../../../../Documents'); } @@ -120,14 +117,17 @@ protected function createTestDocumentManager(): DocumentManager return DocumentManager::create($client, $config); } - protected function getServerVersion() + protected function getServerVersion(): string { $result = $this->dm->getClient()->selectDatabase(DOCTRINE_MONGODB_DATABASE)->command(['buildInfo' => 1])->toArray()[0]; return $result['version']; } - protected function skipTestIfNotSharded($className): void + /** + * @psalm-param class-string $className + */ + protected function skipTestIfNotSharded(string $className): void { $result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0]; @@ -138,7 +138,10 @@ protected function skipTestIfNotSharded($className): void $this->markTestSkipped('Test skipped because server does not support sharding'); } - protected function skipTestIfSharded($className): void + /** + * @psalm-param class-string $className + */ + protected function skipTestIfSharded(string $className): void { $result = $this->dm->getDocumentDatabase($className)->command(['listCommands' => true])->toArray()[0]; @@ -149,7 +152,7 @@ protected function skipTestIfSharded($className): void $this->markTestSkipped('Test does not apply on sharded clusters'); } - protected function requireVersion($installedVersion, $requiredVersion, $operator, $message): void + protected function requireVersion(string $installedVersion, string $requiredVersion, ?string $operator, string $message): void { if (! version_compare($installedVersion, $requiredVersion, $operator)) { return; @@ -158,12 +161,12 @@ protected function requireVersion($installedVersion, $requiredVersion, $operator $this->markTestSkipped($message); } - protected function skipOnMongoDB42($message): void + protected function skipOnMongoDB42(string $message): void { $this->requireVersion($this->getServerVersion(), '4.2.0', '>=', $message); } - protected function requireMongoDB42($message): void + protected function requireMongoDB42(string $message): void { $this->requireVersion($this->getServerVersion(), '4.2.0', '<', $message); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php index 4470c26df6..5b6265f5ff 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php @@ -277,14 +277,14 @@ public function __construct(string $name, bool $enabled) class MyEmbedsCollection extends ArrayCollection { - public function getByName($name) + public function getByName(string $name): MyEmbedsCollection { return $this->filter(static function ($item) use ($name) { return $item->name === $name; }); } - public function getEnabled() + public function getEnabled(): MyEmbedsCollection { return $this->filter(static function ($item) { return $item->enabled; @@ -305,7 +305,7 @@ public function nothingReally(): void class MyDocumentsCollection extends ArrayCollection { - public function havingEmbeds() + public function havingEmbeds(): MyDocumentsCollection { return $this->filter(static function ($item) { return $item->coll->count(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php index 7f9159c2e8..3b37552b81 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomIdTest.php @@ -81,7 +81,7 @@ public function testBatchInsertCustomId(): void $this->assertCount(2, $users); - $results = []; + $results = ['userId' => false]; foreach ($users as $user) { if ($user->getId() === 'userId') { $results['userId'] = true; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomTypeTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomTypeTest.php index 4c64181dd0..ccf29dfc3b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomTypeTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomTypeTest.php @@ -54,6 +54,8 @@ class DateCollectionType extends Type /** * Method called by PersistenceBuilder + * + * {@inheritDoc} */ public function convertToDatabaseValue($value) { @@ -74,6 +76,9 @@ public function convertToDatabaseValue($value) return $value; } + /** + * {@inheritDoc} + */ public function convertToPHPValue($value) { if ($value === null) { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php index a398ff393f..a1c56b78ae 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DiscriminatorsDefaultValueTest.php @@ -90,18 +90,21 @@ abstract class ParentDocument */ protected $id; - /** @var ChildDocument|null */ + /** @var ChildDocument */ protected $referencedChild; - /** @var ChildDocument[] */ + /** @var Collection|array */ protected $referencedChildren; - /** @var ChildDocument|null */ + /** @var ChildDocument */ protected $embeddedChild; - /** @var ChildDocument[] */ + /** @var Collection|array */ protected $embeddedChildren; + /** + * @param array{0: ChildDocument, 1: ChildDocument} $children + */ public function __construct(array $children) { $this->referencedChild = $children[0]; @@ -115,21 +118,27 @@ public function getId(): ?string return $this->id; } - public function getReferencedChild() + public function getReferencedChild(): ChildDocument { return $this->referencedChild; } + /** + * @return Collection|array + */ public function getReferencedChildren() { return $this->referencedChildren; } - public function getEmbeddedChild() + public function getEmbeddedChild(): ChildDocument { return $this->embeddedChild; } + /** + * @return Collection|array + */ public function getEmbeddedChildren() { return $this->embeddedChildren; @@ -158,12 +167,12 @@ public function __construct(string $type) $this->type = $type; } - public function getId() + public function getId(): ?string { return $this->id; } - public function getType() + public function getType(): string { return $this->type; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php index b5b4dcf432..c9f227331b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php @@ -1035,6 +1035,9 @@ final class DocumentPersisterCustomIdType extends Type { use ClosureToPHP; + /** + * {@inheritdoc} + */ public function convertToDatabaseValue($value) { if ($value instanceof ObjectId) { @@ -1048,6 +1051,9 @@ public function convertToDatabaseValue($value) throw self::createException($value); } + /** + * {@inheritdoc} + */ public function convertToPHPValue($value) { if ($value instanceof DocumentPersisterCustomTypedId) { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php index bd552e5f17..fcf128bb74 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php @@ -86,7 +86,7 @@ public function testRemoveOption(): void $this->assertCount(2, $product->getOptions()); } - protected function getProduct() + protected function getProduct(): ConfigurableProduct { $products = $this->dm->getRepository(ConfigurableProduct::class) ->createQueryBuilder() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php index 8931c85f63..ad7d557dd7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php @@ -157,7 +157,7 @@ public function testRepositoryFindOneBy(): void $this->assertEquals('John', $this->getJohnsUsernameWithFindOneBy()); } - protected function getJohnsUsernameWithFindOneBy() + protected function getJohnsUsernameWithFindOneBy(): ?string { $john = $this->dm->getRepository(User::class)->findOneBy(['id' => $this->ids['john']]); @@ -235,7 +235,7 @@ public function testReferenceOne(): void $this->assertEquals('Timothy', $this->getProfileByReference()); } - protected function getProfileByReference() + protected function getProfileByReference(): ?string { $tim = $this->dm->getRepository(User::class)->find($this->ids['tim']); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php index e48cee20af..75e7804761 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/IdentifiersTest.php @@ -7,6 +7,7 @@ use Doctrine\ODM\MongoDB\Tests\BaseTest; use Documents\Event; use Documents\User; +use ProxyManager\Proxy\LazyLoadingInterface; use function assert; use function get_class; @@ -27,8 +28,10 @@ public function testGetIdentifierValue(): void $test = $this->dm->getRepository(get_class($event))->find($event->getId()); - $this->assertEquals($user->getId(), $test->getUser()->getId()); - $this->assertFalse($test->getUser()->isProxyInitialized()); + $userTest = $test->getUser(); + $this->assertEquals($user->getId(), $userTest->getId()); + $this->assertInstanceOf(LazyLoadingInterface::class, $userTest); + $this->assertFalse($userTest->isProxyInitialized()); $this->dm->clear(); @@ -37,6 +40,7 @@ public function testGetIdentifierValue(): void $test = $this->dm->getRepository(get_class($event))->find($event->getId()); $this->assertEquals($user->getId(), $class->getIdentifierValue($test->getUser())); $this->assertEquals($user->getId(), $class->getFieldValue($test->getUser(), 'id')); + $this->assertInstanceOf(LazyLoadingInterface::class, $test->getUser()); $this->assertFalse($test->getUser()->isProxyInitialized()); $this->assertEquals('jwage', $test->getUser()->getUsername()); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php index 41f704bdd0..6d81a510ed 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/MappedSuperclassTest.php @@ -67,7 +67,7 @@ public function setMapped1($val): void $this->mapped1 = $val; } - public function getMapped1() + public function getMapped1(): ?string { return $this->mapped1; } @@ -77,7 +77,7 @@ public function setMapped2($val): void $this->mapped2 = $val; } - public function getMapped2() + public function getMapped2(): ?string { return $this->mapped2; } @@ -87,7 +87,7 @@ public function setMappedRelated1($mappedRelated1): void $this->mappedRelated1 = $mappedRelated1; } - public function getMappedRelated1() + public function getMappedRelated1(): ?MappedSuperclassRelated1 { return $this->mappedRelated1; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php index 8b15a2fb2d..81ffcda4ed 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php @@ -112,8 +112,8 @@ public function testNestedReference(): void $test = $this->dm->getRepository(Hierarchy::class)->findOneBy(['name' => 'Root']); $this->assertNotNull($test); - $child1 = $test->getChild('Child 1')->setName('Child 1 Changed'); - $child2 = $test->getChild('Child 2')->setName('Child 2 Changed'); + $test->getChild('Child 1')->setName('Child 1 Changed'); + $test->getChild('Child 2')->setName('Child 2 Changed'); $test->setName('Root Changed'); $child3 = $test->addChild('Child 3'); $this->dm->persist($child3); @@ -184,6 +184,11 @@ public function getName(): string return $this->name; } + /** + * @param int|string $name + * + * @return Hierarchy|null + */ public function getChild($name) { if (is_numeric($name)) { @@ -199,6 +204,11 @@ public function getChild($name) return null; } + /** + * @param string|Hierarchy $child + * + * @return Hierarchy + */ public function addChild($child) { if (is_string($child)) { @@ -210,7 +220,10 @@ public function addChild($child) return $child; } - public function getChildren(): array + /** + * @return Collection|array + */ + public function getChildren() { return $this->children; } @@ -249,6 +262,11 @@ public function getName(): string return $this->name; } + /** + * @param string|int $name + * + * @return ChildCategory|null + */ public function getChild($name) { if (is_numeric($name)) { @@ -264,6 +282,11 @@ public function getChild($name) return null; } + /** + * @param string|ChildCategory $child + * + * @return ChildCategory + */ public function addChild($child) { if (is_string($child)) { @@ -275,6 +298,9 @@ public function addChild($child) return $child; } + /** + * @return Collection + */ public function getChildren(): Collection { return $this->children; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php index 153f2aa926..7e004b7fee 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php @@ -11,6 +11,7 @@ use Doctrine\ODM\MongoDB\Iterator\Iterator; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\PersistentCollection; +use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface; use Doctrine\ODM\MongoDB\Tests\BaseTest; use Documents\Account; use Documents\Address; @@ -206,6 +207,7 @@ public function testManyReference(): void $user2 = $query->getSingleResult(); assert($user2 instanceof User); $groups = $user2->getGroups(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $groups); $this->assertFalse($groups->isInitialized()); $groups->count(); @@ -255,6 +257,7 @@ public function testFlushInitializesEmptyPersistentCollection(): void $this->dm->persist($user); $this->dm->flush(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getGroups()); $this->assertTrue($user->getGroups()->isInitialized(), 'A flushed collection should be initialized'); $this->assertCount(2, $user->getGroups()); $this->assertCount(2, $user->getGroups()->toArray()); @@ -277,6 +280,7 @@ public function testFlushInitializesNotEmptyPersistentCollection(): void $this->dm->persist($user); $this->dm->flush(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getGroups()); $this->assertTrue($user->getGroups()->isInitialized(), 'A flushed collection should be initialized'); $this->assertCount(3, $user->getGroups()); $this->assertCount(3, $user->getGroups()->toArray()); @@ -308,6 +312,7 @@ public function testManyReferenceWithAddToSetStrategy(): void assert($user2 instanceof User); $groups = $user2->getUniqueGroups(); + $this->assertInstanceOf(PersistentCollection\PersistentCollectionInterface::class, $groups); $this->assertFalse($groups->isInitialized()); $groups->count(); @@ -495,6 +500,7 @@ public function testDocumentNotFoundEvent(): void $this->dm->getEventManager()->addEventListener(Events::documentNotFound, new DocumentNotFoundListener($closure)); + $this->assertInstanceOf(LazyLoadingInterface::class, $profile); $profile->initializeProxy(); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1058Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1058Test.php index afd21af33c..a8662908cc 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1058Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1058Test.php @@ -78,7 +78,7 @@ class GH1058PersistDocument */ private $value; - public function getId() + public function getId(): ?string { return $this->id; } @@ -106,7 +106,7 @@ class GH1058UpsertDocument */ private $value; - public function getId() + public function getId(): ?string { return $this->id; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH267Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH267Test.php index fccb5115a0..f0dc77b84d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH267Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH267Test.php @@ -93,7 +93,7 @@ public function setId(string $id): void $this->id = $id; } - public function getId() + public function getId(): ?string { return $this->id; } @@ -146,7 +146,7 @@ public function setId($id): void $this->id = $id; } - public function getId() + public function getId(): ?string { return $this->id; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php index ff1100568c..d60685c1c6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH593Test.php @@ -138,7 +138,7 @@ public function __construct() } /** Return the identifier without triggering Proxy initialization */ - public function getId() + public function getId(): ?string { return $this->id; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php index 161427d8c1..ca6cf2db14 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH597Test.php @@ -150,7 +150,7 @@ public function __construct() $this->referenceMany = new ArrayCollection(); } - public function getId() + public function getId(): ?string { return $this->id; } @@ -205,7 +205,7 @@ public function __construct($field) $this->field = $field; } - public function getId() + public function getId(): ?string { return $this->id; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php index 98e9e26d16..67b894ee18 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH602Test.php @@ -132,7 +132,7 @@ public function __construct() } /** Return the identifier without triggering Proxy initialization */ - public function getId() + public function getId(): ?string { return $this->id; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH774Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH774Test.php index 6fe761f79b..e42169bc53 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH774Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH774Test.php @@ -6,6 +6,7 @@ use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver; use Doctrine\ODM\MongoDB\Tests\BaseTest; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; use MongoDB\BSON\ObjectId; use function get_class; @@ -29,7 +30,7 @@ public function testUpsert(): void $this->assertEquals('test', $thread->permalink); } - protected function createMetadataDriverImpl() + protected function createMetadataDriverImpl(): MappingDriver { return new XmlDriver(__DIR__ . '/GH774'); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php index d317b52940..52ac8bfba6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH909Test.php @@ -26,6 +26,7 @@ public function testManyReferenceAddAndPersist(): void $groups = $user->getGroups(); $this->assertCount(2, $groups); + $this->assertInstanceOf(PersistentCollectionInterface::class, $groups); $this->assertTrue($groups->isInitialized()); $user->addGroup(new Group('Group C')); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH999Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH999Test.php index 89dbc8f123..a241920d82 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH999Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH999Test.php @@ -65,12 +65,12 @@ public function __construct($name) $this->name = $name; } - public function getId() + public function getId(): ?string { return $this->id; } - public function getName() + public function getName(): ?string { return $this->name; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php index 277287e4de..1002f3c6a6 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM45Test.php @@ -72,7 +72,7 @@ public function setVal($val): void $this->val = $val; } - public function getVal() + public function getVal(): ?string { return $this->val; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php index e7f238b8ac..0e84982640 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM47Test.php @@ -46,7 +46,7 @@ public function renameC($c): void $this->b = $c; } - public function getId() + public function getId(): ?string { return $this->id; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php index 136f181465..101642d270 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM48Test.php @@ -47,12 +47,12 @@ class MODM48A */ public $b; - public function getId() + public function getId(): ?string { return $this->id; } - public function getB() + public function getB(): ?MODM48B { return $this->b; } @@ -78,7 +78,7 @@ public function setVal($val): void $this->val = $val; } - public function getVal() + public function getVal(): ?string { return $this->val; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM70Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM70Test.php index 08971dfac8..fb394a8514 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM70Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM70Test.php @@ -4,6 +4,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; +use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Tests\BaseTest; @@ -62,18 +63,21 @@ class Avatar * name="aP" * ) * - * @var array AvatarPart + * @var Collection|array */ protected $avatarParts; - public function __construct($name, $sex, $avatarParts = null) + /** + * @param AvatarPart[] $avatarParts + */ + public function __construct(string $name, int $sex, ?array $avatarParts = null) { $this->name = $name; $this->sex = $sex; $this->avatarParts = $avatarParts; } - public function getId() + public function getId(): ?string { return $this->id; } @@ -83,7 +87,7 @@ public function getName(): string return $this->name; } - public function setName($name): void + public function setName(string $name): void { $this->name = $name; } @@ -93,29 +97,35 @@ public function getSex(): int return $this->sex; } - public function setSex($sex): void + public function setSex(int $sex): void { $this->sex = $sex; } + /** + * @return Collection|array|null + */ public function getAvatarParts() { return $this->avatarParts; } - public function addAvatarPart($part): void + public function addAvatarPart(AvatarPart $part): void { $this->avatarParts[] = $part; } - public function setAvatarParts($parts): void + /** + * @param AvatarPart[] $parts + */ + public function setAvatarParts(array $parts): void { $this->avatarParts = $parts; } - public function removeAvatarPart($part): void + public function removeAvatarPart(AvatarPart $part): void { - $key = array_search($this->avatarParts, $part); + $key = array_search($part, $this->avatarParts); if ($key === false) { return; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/UpsertTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/UpsertTest.php index 6d4bc16515..0cfefb400c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/UpsertTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/UpsertTest.php @@ -38,7 +38,7 @@ public function testUpsertEmbedManyDoesNotCreateObject(): void $this->dm->flush(); } - public function testUpsertDoesNotOverwriteNullableFieldsOnNull() + public function testUpsertDoesNotOverwriteNullableFieldsOnNull(): void { $test = new UpsertTestUser(); @@ -66,7 +66,7 @@ public function testUpsertDoesNotOverwriteNullableFieldsOnNull() self::assertNotNull($upsertResult->nullableEmbedOne); } - public function testUpsertsWritesNullableFieldsOnInsert() + public function testUpsertsWritesNullableFieldsOnInsert(): void { $test = new UpsertTestUser(); $this->dm->persist($test); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTest.php index 74caf1fcbd..cbdd5876a8 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractAnnotationDriverTest.php @@ -10,13 +10,14 @@ use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; use Doctrine\ODM\MongoDB\Mapping\MappingException; use Documents\CmsUser; +use Generator; use stdClass; use function get_class; abstract class AbstractAnnotationDriverTest extends AbstractMappingDriverTest { - public function testFieldInheritance() + public function testFieldInheritance(): void { // @TODO: This can be a generic test for all drivers $super = $this->dm->getClassMetadata(AnnotationDriverTestSuper::class); @@ -71,7 +72,7 @@ public function testFieldInheritance() /** * @group DDC-268 */ - public function testLoadMetadataForNonDocumentThrowsException() + public function testLoadMetadataForNonDocumentThrowsException(): void { $cm = new ClassMetadata('stdClass'); $reader = new AnnotationReader(); @@ -84,7 +85,7 @@ public function testLoadMetadataForNonDocumentThrowsException() /** * @group DDC-268 */ - public function testColumnWithMissingTypeDefaultsToString() + public function testColumnWithMissingTypeDefaultsToString(): void { $cm = new ClassMetadata(ColumnWithoutType::class); $reader = new AnnotationReader(); @@ -97,7 +98,7 @@ public function testColumnWithMissingTypeDefaultsToString() /** * @group DDC-318 */ - public function testGetAllClassNamesIsIdempotent() + public function testGetAllClassNamesIsIdempotent(): void { $annotationDriver = $this->loadDriverForCMSDocuments(); $original = $annotationDriver->getAllClassNames(); @@ -111,7 +112,7 @@ public function testGetAllClassNamesIsIdempotent() /** * @group DDC-318 */ - public function testGetAllClassNamesIsIdempotentEvenWithDifferentDriverInstances() + public function testGetAllClassNamesIsIdempotentEvenWithDifferentDriverInstances(): void { $annotationDriver = $this->loadDriverForCMSDocuments(); $original = $annotationDriver->getAllClassNames(); @@ -125,7 +126,7 @@ public function testGetAllClassNamesIsIdempotentEvenWithDifferentDriverInstances /** * @group DDC-318 */ - public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate() + public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate(): void { $annotationDriver = $this->loadDriverForCMSDocuments(); $classes = $annotationDriver->getAllClassNames(); @@ -136,7 +137,7 @@ public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate() /** * @group DDC-318 */ - public function testGetClassNamesReturnsOnlyTheAppropriateClasses() + public function testGetClassNamesReturnsOnlyTheAppropriateClasses(): void { $extraneousClassName = ColumnWithoutType::class; @@ -146,14 +147,14 @@ public function testGetClassNamesReturnsOnlyTheAppropriateClasses() $this->assertNotContains($extraneousClassName, $classes); } - public function testEmbeddedClassCantHaveShardKey() + public function testEmbeddedClassCantHaveShardKey(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage('Embedded document can\'t have shard key'); $this->dm->getClassMetadata(AnnotationDriverEmbeddedWithShardKey::class); } - public function testDocumentAnnotationCanSpecifyWriteConcern() + public function testDocumentAnnotationCanSpecifyWriteConcern(): void { $cm = $this->dm->getClassMetadata(AnnotationDriverTestWriteConcernMajority::class); $this->assertEquals('majority', $cm->writeConcern); @@ -168,7 +169,7 @@ public function testDocumentAnnotationCanSpecifyWriteConcern() /** * @dataProvider provideClassCanBeMappedByOneAbstractDocument */ - public function testClassCanBeMappedByOneAbstractDocument(object $wrong, string $messageRegExp) + public function testClassCanBeMappedByOneAbstractDocument(object $wrong, string $messageRegExp): void { $this->expectException(MappingException::class); $this->expectExceptionMessageMatches($messageRegExp); @@ -180,7 +181,7 @@ public function testClassCanBeMappedByOneAbstractDocument(object $wrong, string $annotationDriver->loadMetadataForClass(get_class($wrong), $cm); } - public function provideClassCanBeMappedByOneAbstractDocument() + public function provideClassCanBeMappedByOneAbstractDocument(): ?Generator { yield [ /** @@ -243,7 +244,7 @@ public function provideClassCanBeMappedByOneAbstractDocument() ]; } - public function testWrongValueForValidationValidatorShouldThrowException() + public function testWrongValueForValidationValidatorShouldThrowException(): void { $annotationDriver = $this->loadDriver(); $classMetadata = new ClassMetadata(WrongValueForValidationValidator::class); @@ -252,7 +253,7 @@ public function testWrongValueForValidationValidatorShouldThrowException() $annotationDriver->loadMetadataForClass($classMetadata->name, $classMetadata); } - protected function loadDriverForCMSDocuments() + protected function loadDriverForCMSDocuments(): AnnotationDriver { $annotationDriver = $this->loadDriver(); self::assertInstanceOf(AnnotationDriver::class, $annotationDriver); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php index 7ebff8f509..cf3c2f8592 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTest.php @@ -27,7 +27,7 @@ abstract class AbstractMappingDriverTest extends BaseTest { abstract protected function loadDriver(): MappingDriver; - protected function createMetadataDriverImpl() + protected function createMetadataDriverImpl(): MappingDriver { return $this->loadDriver(); } @@ -35,7 +35,7 @@ protected function createMetadataDriverImpl() /** * @doesNotPerformAssertions */ - public function testLoadMapping() + public function testLoadMapping(): ClassMetadata { return $this->dm->getClassMetadata(AbstractMappingDriverUser::class); } @@ -45,7 +45,7 @@ public function testLoadMapping() * * @depends testLoadMapping */ - public function testDocumentCollectionNameAndInheritance($class) + public function testDocumentCollectionNameAndInheritance($class): ClassMetadata { $this->assertEquals('cms_users', $class->getCollection()); $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType); @@ -58,7 +58,7 @@ public function testDocumentCollectionNameAndInheritance($class) * * @depends testLoadMapping */ - public function testDocumentMarkedAsReadOnly($class) + public function testDocumentMarkedAsReadOnly($class): ClassMetadata { $this->assertTrue($class->isReadOnly); @@ -70,7 +70,7 @@ public function testDocumentMarkedAsReadOnly($class) * * @depends testDocumentCollectionNameAndInheritance */ - public function testDocumentLevelReadPreference($class) + public function testDocumentLevelReadPreference($class): ClassMetadata { $this->assertEquals('primaryPreferred', $class->readPreference); $this->assertEquals([ @@ -87,7 +87,7 @@ public function testDocumentLevelReadPreference($class) * * @depends testDocumentCollectionNameAndInheritance */ - public function testDocumentLevelWriteConcern($class) + public function testDocumentLevelWriteConcern($class): ClassMetadata { $this->assertEquals(1, $class->getWriteConcern()); @@ -99,7 +99,7 @@ public function testDocumentLevelWriteConcern($class) * * @depends testDocumentLevelWriteConcern */ - public function testFieldMappings($class) + public function testFieldMappings($class): ClassMetadata { $this->assertCount(14, $class->fieldMappings); $this->assertTrue(isset($class->fieldMappings['identifier'])); @@ -117,7 +117,7 @@ public function testFieldMappings($class) * * @depends testDocumentCollectionNameAndInheritance */ - public function testAssociationMappings($class) + public function testAssociationMappings($class): void { $this->assertCount(6, $class->associationMappings); $this->assertTrue(isset($class->associationMappings['address'])); @@ -133,7 +133,7 @@ public function testAssociationMappings($class) * * @depends testDocumentCollectionNameAndInheritance */ - public function testGetAssociationTargetClass($class) + public function testGetAssociationTargetClass($class): void { $this->assertEquals(Address::class, $class->getAssociationTargetClass('address')); $this->assertEquals(Group::class, $class->getAssociationTargetClass('groups')); @@ -148,7 +148,7 @@ public function testGetAssociationTargetClass($class) * * @depends testDocumentCollectionNameAndInheritance */ - public function testGetAssociationTargetClassThrowsExceptionWhenEmpty($class) + public function testGetAssociationTargetClassThrowsExceptionWhenEmpty($class): void { $this->expectException(InvalidArgumentException::class); $class->getAssociationTargetClass('invalid_association'); @@ -159,7 +159,7 @@ public function testGetAssociationTargetClassThrowsExceptionWhenEmpty($class) * * @depends testDocumentCollectionNameAndInheritance */ - public function testStringFieldMappings($class) + public function testStringFieldMappings($class): ClassMetadata { $this->assertEquals('string', $class->fieldMappings['name']['type']); @@ -171,7 +171,7 @@ public function testStringFieldMappings($class) * * @depends testFieldMappings */ - public function testIdentifier($class) + public function testIdentifier($class): ClassMetadata { $this->assertEquals('identifier', $class->identifier); @@ -183,7 +183,7 @@ public function testIdentifier($class) * * @depends testFieldMappings */ - public function testVersionFieldMappings($class) + public function testVersionFieldMappings($class): ClassMetadata { $this->assertEquals('int', $class->fieldMappings['version']['type']); $this->assertNotEmpty($class->fieldMappings['version']['version']); @@ -196,7 +196,7 @@ public function testVersionFieldMappings($class) * * @depends testFieldMappings */ - public function testLockFieldMappings($class) + public function testLockFieldMappings($class): ClassMetadata { $this->assertEquals('int', $class->fieldMappings['lock']['type']); $this->assertNotEmpty($class->fieldMappings['lock']['lock']); @@ -209,7 +209,7 @@ public function testLockFieldMappings($class) * * @depends testIdentifier */ - public function testAssocations($class) + public function testAssocations($class): ClassMetadata { $this->assertCount(14, $class->fieldMappings); @@ -221,7 +221,7 @@ public function testAssocations($class) * * @depends testAssocations */ - public function testOwningOneToOneAssocation($class) + public function testOwningOneToOneAssocation($class): ClassMetadata { $this->assertTrue(isset($class->fieldMappings['address'])); $this->assertIsArray($class->fieldMappings['address']); @@ -240,7 +240,7 @@ public function testOwningOneToOneAssocation($class) * * @depends testOwningOneToOneAssocation */ - public function testLifecycleCallbacks($class) + public function testLifecycleCallbacks($class): ClassMetadata { $expectedLifecycleCallbacks = [ 'prePersist' => ['doStuffOnPrePersist', 'doOtherStuffOnPrePersistToo'], @@ -257,7 +257,7 @@ public function testLifecycleCallbacks($class) * * @depends testLifecycleCallbacks */ - public function testCustomFieldName($class) + public function testCustomFieldName($class): ClassMetadata { $this->assertEquals('name', $class->fieldMappings['name']['fieldName']); $this->assertEquals('username', $class->fieldMappings['name']['name']); @@ -270,7 +270,7 @@ public function testCustomFieldName($class) * * @depends testCustomFieldName */ - public function testCustomReferenceFieldName($class) + public function testCustomReferenceFieldName($class): ClassMetadata { $this->assertEquals('morePhoneNumbers', $class->fieldMappings['morePhoneNumbers']['fieldName']); $this->assertEquals('more_phone_numbers', $class->fieldMappings['morePhoneNumbers']['name']); @@ -283,7 +283,7 @@ public function testCustomReferenceFieldName($class) * * @depends testCustomReferenceFieldName */ - public function testCustomEmbedFieldName($class) + public function testCustomEmbedFieldName($class): ClassMetadata { $this->assertEquals('embeddedPhonenumber', $class->fieldMappings['embeddedPhonenumber']['fieldName']); $this->assertEquals('embedded_phone_number', $class->fieldMappings['embeddedPhonenumber']['name']); @@ -296,7 +296,7 @@ public function testCustomEmbedFieldName($class) * * @depends testCustomEmbedFieldName */ - public function testDiscriminator($class) + public function testDiscriminator($class): ClassMetadata { $this->assertTrue(isset($class->discriminatorField)); $this->assertTrue(isset($class->discriminatorMap)); @@ -313,7 +313,7 @@ public function testDiscriminator($class) * * @depends testDiscriminator */ - public function testEmbedDiscriminator($class) + public function testEmbedDiscriminator($class): ClassMetadata { $this->assertTrue(isset($class->fieldMappings['otherPhonenumbers']['discriminatorField'])); $this->assertTrue(isset($class->fieldMappings['otherPhonenumbers']['discriminatorMap'])); @@ -333,7 +333,7 @@ public function testEmbedDiscriminator($class) * * @depends testEmbedDiscriminator */ - public function testReferenceDiscriminator($class) + public function testReferenceDiscriminator($class): ClassMetadata { $this->assertTrue(isset($class->fieldMappings['phonenumbers']['discriminatorField'])); $this->assertTrue(isset($class->fieldMappings['phonenumbers']['discriminatorMap'])); @@ -353,7 +353,7 @@ public function testReferenceDiscriminator($class) * * @depends testCustomFieldName */ - public function testIndexes($class) + public function testIndexes($class): ClassMetadata { $indexes = $class->indexes; @@ -401,7 +401,7 @@ public function testIndexes($class) * * @depends testIndexes */ - public function testShardKey($class) + public function testShardKey($class): void { $shardKey = $class->getShardKey(); @@ -414,7 +414,7 @@ public function testShardKey($class) $this->assertEquals(4096, $shardKey['options']['numInitialChunks'], 'Shard key option has wrong value'); } - public function testGridFSMapping() + public function testGridFSMapping(): void { $class = $this->dm->getClassMetadata(AbstractMappingDriverFile::class); @@ -459,7 +459,7 @@ public function testGridFSMapping() ], $class->getFieldMapping('metadata'), true); } - public function testGridFSMappingWithCustomRepository() + public function testGridFSMappingWithCustomRepository(): void { $class = $this->dm->getClassMetadata(AbstractMappingDriverFileWithCustomRepository::class); @@ -467,7 +467,7 @@ public function testGridFSMappingWithCustomRepository() $this->assertSame(AbstractMappingDriverGridFSRepository::class, $class->customRepositoryClassName); } - public function testDuplicateDatabaseNameInMappingCauseErrors() + public function testDuplicateDatabaseNameInMappingCauseErrors(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage( @@ -477,7 +477,7 @@ public function testDuplicateDatabaseNameInMappingCauseErrors() $this->dm->getClassMetadata(AbstractMappingDriverDuplicateDatabaseName::class); } - public function testDuplicateDatabaseNameWithNotSavedDoesNotThrowExeption() + public function testDuplicateDatabaseNameWithNotSavedDoesNotThrowExeption(): void { $metadata = $this->dm->getClassMetadata(AbstractMappingDriverDuplicateDatabaseNameNotSaved::class); @@ -486,7 +486,7 @@ public function testDuplicateDatabaseNameWithNotSavedDoesNotThrowExeption() $this->assertTrue($metadata->fieldMappings['bar']['notSaved']); } - public function testViewWithoutRepository() + public function testViewWithoutRepository(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( @@ -499,7 +499,7 @@ public function testViewWithoutRepository() $this->dm->getRepository(AbstractMappingDriverViewWithoutRepository::class); } - public function testViewWithWrongRepository() + public function testViewWithWrongRepository(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( @@ -512,7 +512,7 @@ public function testViewWithWrongRepository() $this->dm->getRepository(AbstractMappingDriverViewWithWrongRepository::class); } - public function testViewWithoutRootClass() + public function testViewWithoutRootClass(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( @@ -523,7 +523,7 @@ public function testViewWithoutRootClass() $this->dm->getClassMetadata(AbstractMappingDriverViewWithoutRootClass::class); } - public function testViewWithNonExistingRootClass() + public function testViewWithNonExistingRootClass(): void { $this->expectException(MappingException::class); $this->expectExceptionMessage(sprintf( @@ -535,7 +535,7 @@ public function testViewWithNonExistingRootClass() $this->dm->getClassMetadata(AbstractMappingDriverViewWithNonExistingRootClass::class); } - public function testView() + public function testView(): void { $metadata = $this->dm->getClassMetadata(AbstractMappingDriverView::class); @@ -727,7 +727,7 @@ class AbstractMappingDriverUser * @ODM\PrePersist */ #[ODM\PrePersist] - public function doStuffOnPrePersist() + public function doStuffOnPrePersist(): void { } @@ -735,7 +735,7 @@ public function doStuffOnPrePersist() * @ODM\PrePersist */ #[ODM\PrePersist] - public function doOtherStuffOnPrePersistToo() + public function doOtherStuffOnPrePersistToo(): void { } @@ -743,11 +743,11 @@ public function doOtherStuffOnPrePersistToo() * @ODM\PostPersist */ #[ODM\PostPersist] - public function doStuffOnPostPersist() + public function doStuffOnPostPersist(): void { } - public static function loadMetadata(ClassMetadata $metadata) + public static function loadMetadata(ClassMetadata $metadata): void { $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_NONE); $metadata->setCollection('cms_users'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php index 54b695665f..c56647474d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php @@ -23,7 +23,7 @@ protected function loadDriver(): MappingDriver return new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml'); } - public function testSetShardKeyOptionsByAttributes() + public function testSetShardKeyOptionsByAttributes(): void { $class = new ClassMetadata(stdClass::class); $driver = $this->loadDriver(); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Tools/GH297/Address.php b/tests/Doctrine/ODM/MongoDB/Tests/Tools/GH297/Address.php index d297e9ebb4..bb49082339 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Tools/GH297/Address.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Tools/GH297/Address.php @@ -16,7 +16,7 @@ class Address */ private $street; - public function getStreet() + public function getStreet(): ?string { return $this->street; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php index fcdd65c8fa..cdc4e48ae0 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Tools/ResolveTargetDocumentListenerTest.php @@ -152,7 +152,7 @@ class TargetDocument implements TargetInterface */ private $id; - public function getId() + public function getId(): ?string { return $this->id; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php index 7c60cef0cb..f1c5253f06 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php @@ -600,7 +600,7 @@ public function __construct() $this->items = new ArrayCollection(); } - public function getId() + public function getId(): ?int { return $this->id; } @@ -610,7 +610,7 @@ public function setId($id): void $this->id = $id; } - public function getData() + public function getData(): ?string { return $this->data; } @@ -670,7 +670,7 @@ class NotifyChangedRelatedItem */ private $owner; - public function getId() + public function getId(): ?int { return $this->id; } @@ -680,7 +680,7 @@ public function setId($id): void $this->id = $id; } - public function getOwner() + public function getOwner(): ?NotifyChangedDocument { return $this->owner; } diff --git a/tests/Documents/Account.php b/tests/Documents/Account.php index 18b26885c5..076ee3ada9 100644 --- a/tests/Documents/Account.php +++ b/tests/Documents/Account.php @@ -52,11 +52,17 @@ public function getName(): ?string return $this->name; } + /** + * @param User|CustomUser $user + */ public function setUser($user): void { $this->user = $user; } + /** + * @return CustomUser|User|null + */ public function getUser() { return $this->user; diff --git a/tests/Documents/Address.php b/tests/Documents/Address.php index 6c68db066d..34098d6dc1 100644 --- a/tests/Documents/Address.php +++ b/tests/Documents/Address.php @@ -63,12 +63,12 @@ public function setSubAddress(Address $subAddress): void $this->subAddress = $subAddress; } - public function getSubAddress() + public function getSubAddress(): ?Address { return $this->subAddress; } - public function getAddress() + public function getAddress(): ?string { return $this->address; } @@ -78,7 +78,7 @@ public function setAddress($address): void $this->address = $address; } - public function getCity() + public function getCity(): ?string { return $this->city; } @@ -88,7 +88,7 @@ public function setCity($city): void $this->city = $city; } - public function getState() + public function getState(): ?string { return $this->state; } @@ -98,7 +98,7 @@ public function setState($state): void $this->state = $state; } - public function getZipcode() + public function getZipcode(): ?string { return $this->zipcode; } diff --git a/tests/Documents/Album.php b/tests/Documents/Album.php index e3bad20f3a..0c300295cd 100644 --- a/tests/Documents/Album.php +++ b/tests/Documents/Album.php @@ -38,7 +38,7 @@ public function __construct($name) $this->songs = new ArrayCollection(); } - public function getId() + public function getId(): ?string { return $this->id; } @@ -48,7 +48,7 @@ public function setName($name): void $this->name = $name; } - public function getName() + public function getName(): ?string { return $this->name; } diff --git a/tests/Documents/Article.php b/tests/Documents/Article.php index 445fd48421..a3b0b030be 100644 --- a/tests/Documents/Article.php +++ b/tests/Documents/Article.php @@ -51,12 +51,12 @@ class Article */ private $tags = []; - public function getId() + public function getId(): ?string { return $this->id; } - public function getTitle() + public function getTitle(): ?string { return $this->title; } @@ -66,21 +66,27 @@ public function setTitle($title): void $this->title = $title; } - public function getBody() + public function getBody(): ?string { return $this->body; } - public function setBody($body): void + public function setBody(string $body): void { $this->body = $body; } + /** + * @return DateTimeInterface|UTCDateTime|string|null + */ public function getCreatedAt() { return $this->createdAt; } + /** + * @param DateTimeInterface|UTCDateTime|string|null $createdAt + */ public function setCreatedAt($createdAt): void { $this->createdAt = $createdAt; diff --git a/tests/Documents/Bars/Bar.php b/tests/Documents/Bars/Bar.php index a1b67d6920..352f17c17b 100644 --- a/tests/Documents/Bars/Bar.php +++ b/tests/Documents/Bars/Bar.php @@ -32,23 +32,23 @@ class Bar */ private $locations; - public function __construct($name = null) + public function __construct(?string $name = null) { $this->name = $name; $this->locations = new ArrayCollection(); } - public function getId() + public function getId(): ?string { return $this->id; } - public function setName($name): void + public function setName(string $name): void { $this->name = $name; } - public function getName() + public function getName(): ?string { return $this->name; } diff --git a/tests/Documents/Bars/Location.php b/tests/Documents/Bars/Location.php index e64f1ae365..d9c4cffd5c 100644 --- a/tests/Documents/Bars/Location.php +++ b/tests/Documents/Bars/Location.php @@ -16,17 +16,17 @@ class Location */ private $name; - public function __construct($name = null) + public function __construct(?string $name = null) { $this->name = $name; } - public function setName($name): void + public function setName(string $name): void { $this->name = $name; } - public function getName() + public function getName(): ?string { return $this->name; } diff --git a/tests/Documents/BaseCategory.php b/tests/Documents/BaseCategory.php index d774ca71d6..5cb905892f 100644 --- a/tests/Documents/BaseCategory.php +++ b/tests/Documents/BaseCategory.php @@ -34,7 +34,7 @@ public function setName($name): void $this->name = $name; } - public function getName() + public function getName(): ?string { return $this->name; } diff --git a/tests/Documents/BaseDocument.php b/tests/Documents/BaseDocument.php index a780e1ecc5..55342d1765 100644 --- a/tests/Documents/BaseDocument.php +++ b/tests/Documents/BaseDocument.php @@ -24,7 +24,7 @@ public function setInheritedProperty($value): void $this->inheritedProperty = $value; } - public function getInheritedProperty() + public function getInheritedProperty(): ?string { return $this->inheritedProperty; } diff --git a/tests/Documents/BaseEmployee.php b/tests/Documents/BaseEmployee.php index edbdda92e5..567787b704 100644 --- a/tests/Documents/BaseEmployee.php +++ b/tests/Documents/BaseEmployee.php @@ -66,7 +66,7 @@ abstract class BaseEmployee */ protected $address; - public function getId() + public function getId(): ?string { return $this->id; } @@ -102,7 +102,7 @@ public function addNote($note): BaseEmployee return $this; } - public function getName() + public function getName(): ?string { return $this->name; } @@ -114,7 +114,7 @@ public function setName($val): BaseEmployee return $this; } - public function getSalary() + public function getSalary(): ?float { return $this->salary; } @@ -126,7 +126,7 @@ public function setSalary($val): BaseEmployee return $this; } - public function getStarted() + public function getStarted(): ?DateTime { return $this->started; } @@ -138,7 +138,7 @@ public function setStarted($val): BaseEmployee return $this; } - public function getLeft() + public function getLeft(): ?DateTime { return $this->left; } @@ -150,7 +150,7 @@ public function setLeft($val): BaseEmployee return $this; } - public function getAddress() + public function getAddress(): ?Address { return $this->address; } diff --git a/tests/Documents/BlogPost.php b/tests/Documents/BlogPost.php index 6aa0a2b535..956e697189 100644 --- a/tests/Documents/BlogPost.php +++ b/tests/Documents/BlogPost.php @@ -113,7 +113,7 @@ public function __construct(?string $name = null) $this->name = $name; } - public function getName() + public function getName(): ?string { return $this->name; } diff --git a/tests/Documents/CmsAddress.php b/tests/Documents/CmsAddress.php index 1c3802bf43..63f7bb6c30 100644 --- a/tests/Documents/CmsAddress.php +++ b/tests/Documents/CmsAddress.php @@ -49,27 +49,27 @@ class CmsAddress */ public $user; - public function getId() + public function getId(): ?string { return $this->id; } - public function getUser() + public function getUser(): ?CmsUser { return $this->user; } - public function getCountry() + public function getCountry(): ?string { return $this->country; } - public function getZipCode() + public function getZipCode(): ?string { return $this->zip; } - public function getCity() + public function getCity(): ?string { return $this->city; } diff --git a/tests/Documents/CmsComment.php b/tests/Documents/CmsComment.php index a8622611cb..59ed4edade 100644 --- a/tests/Documents/CmsComment.php +++ b/tests/Documents/CmsComment.php @@ -61,7 +61,7 @@ public function setArticle(CmsArticle $article): void $this->article = $article; } - public function __toString() + public function __toString(): string { return self::class . '[id=' . $this->id . ']'; } diff --git a/tests/Documents/CmsUser.php b/tests/Documents/CmsUser.php index e4f36bba9b..2910195dea 100644 --- a/tests/Documents/CmsUser.php +++ b/tests/Documents/CmsUser.php @@ -81,22 +81,22 @@ public function __construct() $this->groups = new ArrayCollection(); } - public function getId() + public function getId(): ?string { return $this->id; } - public function getStatus() + public function getStatus(): ?string { return $this->status; } - public function getUsername() + public function getUsername(): ?string { return $this->username; } - public function getName() + public function getName(): ?string { return $this->name; } @@ -145,7 +145,7 @@ public function removePhonenumber($index): bool return false; } - public function getAddress() + public function getAddress(): CmsAddress { return $this->address; } diff --git a/tests/Documents/CommentRepository.php b/tests/Documents/CommentRepository.php index c81d3a4a49..43ecb96fc5 100644 --- a/tests/Documents/CommentRepository.php +++ b/tests/Documents/CommentRepository.php @@ -14,6 +14,9 @@ */ class CommentRepository extends DocumentRepository { + /** + * @return Comment|false + */ public function findOneComment() { return $this->getDocumentPersister() diff --git a/tests/Documents/CustomUser.php b/tests/Documents/CustomUser.php index c55ab8b25a..ef3e514c16 100644 --- a/tests/Documents/CustomUser.php +++ b/tests/Documents/CustomUser.php @@ -37,7 +37,7 @@ class CustomUser */ protected $account; - public function getId() + public function getId(): ?string { return $this->id; } @@ -52,7 +52,7 @@ public function setUsername($username): void $this->username = $username; } - public function getUsername() + public function getUsername(): ?string { return $this->username; } @@ -62,7 +62,7 @@ public function setPassword($password): void $this->password = $password; } - public function getPassword() + public function getPassword(): ?string { return $this->password; } @@ -73,7 +73,7 @@ public function setAccount(Account $account): void $this->account->setUser($this); } - public function getAccount() + public function getAccount(): ?Account { return $this->account; } diff --git a/tests/Documents/Developer.php b/tests/Documents/Developer.php index 7589e3b3c5..70d2573620 100644 --- a/tests/Documents/Developer.php +++ b/tests/Documents/Developer.php @@ -40,12 +40,15 @@ public function __construct(string $name, ?Collection $projects = null) $this->projects = $projects ?? new ArrayCollection(); } - public function getId() + public function getId(): ?string { return $this->id; } - public function getProjects() + /** + * @return Collection + */ + public function getProjects(): Collection { return $this->projects; } diff --git a/tests/Documents/Ecommerce/ConfigurableProduct.php b/tests/Documents/Ecommerce/ConfigurableProduct.php index 70b498349c..325f12a4b5 100644 --- a/tests/Documents/Ecommerce/ConfigurableProduct.php +++ b/tests/Documents/Ecommerce/ConfigurableProduct.php @@ -41,24 +41,23 @@ class ConfigurableProduct /** @var Option */ protected $selectedOption; - public function __construct($name) + public function __construct(string $name) { $this->setName($name); } - public function getId() + public function getId(): ?string { return $this->id; } - public function getName() + public function getName(): ?string { return $this->name; } - public function setName($name): ConfigurableProduct + public function setName(string $name): ConfigurableProduct { - $name = (string) $name; if (empty($name)) { throw new InvalidArgumentException('Product name cannot be empty'); } @@ -68,6 +67,9 @@ public function setName($name): ConfigurableProduct return $this; } + /*** + * @return Collection|array