diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php index 214c1e2ff8..da7e9e5104 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php @@ -453,6 +453,7 @@ public function testReplacementOfEmbedManyElements() $firstChapter->name = 'First chapter A'; // Developers commonly attempt to replace the contents of an EmbedMany with a new ArrayCollection like this: + /** @var ArrayCollection $replacementChapters */ $replacementChapters = new ArrayCollection(); $replacementChapters->add($firstChapter); $replacementChapters->add(new Chapter('Second chapter B')); @@ -478,9 +479,10 @@ public function testReplacementOfIdentifiedEmbedManyElements() $this->dm->flush(); $this->dm->clear(); - $book = $this->dm->getRepository(Book::CLASSNAME)->findOneBy(['_id' => $book->id]); - $firstChapter = $book->identifiedChapters->first(); - $firstChapter->name = 'First chapter A'; + $book = $this->dm->getRepository(Book::CLASSNAME)->findOneBy(['_id' => $book->id]); + $firstChapter = $book->identifiedChapters->first(); + $firstChapter->name = 'First chapter A'; + /** @var ArrayCollection $replacementChapters */ $replacementChapters = new ArrayCollection(); $replacementChapters->add($firstChapter); $replacementChapters->add(new IdentifiedChapter('Second chapter B')); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php index 39cdc11ed1..8e1b9b54b8 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\PersistentCollection; use Doctrine\ODM\MongoDB\Tests\BaseTest; @@ -560,6 +561,8 @@ public function testWhenCopyingManyEmbedSubDocumentsFromOneDocumentToAnotherWill $this->dm->persist($test1); $this->dm->flush(); + assert($test1->embedMany instanceof Collection); + $test2 = new ChangeEmbeddedIdTest(); $test2->embedMany = $test1->embedMany; //using clone will work $this->dm->persist($test2); @@ -642,10 +645,18 @@ class ChangeEmbeddedIdTest /** @ODM\Id */ public $id; - /** @ODM\EmbedOne(targetDocument=EmbeddedDocumentWithId::class) */ + /** + * @ODM\EmbedOne(targetDocument=EmbeddedDocumentWithId::class) + * + * @var EmbeddedDocumentWithId|null + */ public $embed; - /** @ODM\EmbedMany(targetDocument=EmbeddedDocumentWithId::class) */ + /** + * @ODM\EmbedMany(targetDocument=EmbeddedDocumentWithId::class) + * + * @var Collection|array + */ public $embedMany; public function __construct() diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php index 9a899a9207..0ac50c0aad 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php @@ -22,6 +22,7 @@ public function testSavesEmbeddedDocumentsInReferencedDocument() $project = $this->dm->find(Project::class, $project->getId()); + /** @var ArrayCollection $subProjects */ $subProjects = new ArrayCollection(); $subProject1 = new SubProject('Sub Project #1'); $subProject2 = new SubProject('Sub Project #2'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php index c861c7c019..14c7ef60e7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php @@ -5,6 +5,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface; use Doctrine\ODM\MongoDB\Tests\BaseTest; @@ -20,6 +21,7 @@ public function testClearCollection() $doc->embeds->clear(); $doc->embeds->add(new GH1011Embedded('test2')); $this->uow->computeChangeSets(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $doc->embeds); $this->assertTrue($this->uow->isCollectionScheduledForUpdate($doc->embeds)); $this->assertFalse($this->uow->isCollectionScheduledForDeletion($doc->embeds)); } @@ -47,7 +49,11 @@ class GH1011Document /** @ODM\Id */ public $id; - /** @ODM\EmbedMany(targetDocument=GH1011Embedded::class, strategy="set") */ + /** + * @ODM\EmbedMany(targetDocument=GH1011Embedded::class, strategy="set") + * + * @var Collection + */ public $embeds; public function __construct() diff --git a/tests/Documents/Book.php b/tests/Documents/Book.php index e5d87a33bd..c6459f2893 100644 --- a/tests/Documents/Book.php +++ b/tests/Documents/Book.php @@ -5,6 +5,7 @@ namespace Documents; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\Document */ @@ -18,10 +19,18 @@ class Book /** @ODM\Field(type="int") @ODM\Version */ public $version = 1; - /** @ODM\EmbedMany(targetDocument=Chapter::class, strategy="atomicSet") */ + /** + * @ODM\EmbedMany(targetDocument=Chapter::class, strategy="atomicSet") + * + * @var Collection + */ public $chapters; - /** @ODM\EmbedMany(targetDocument=IdentifiedChapter::class, strategy="atomicSet") */ + /** + * @ODM\EmbedMany(targetDocument=IdentifiedChapter::class, strategy="atomicSet") + * + * @var Collection + */ public $identifiedChapters; public function __construct() diff --git a/tests/Documents/IdentifiedChapter.php b/tests/Documents/IdentifiedChapter.php index d14623cc66..b9697da1ac 100644 --- a/tests/Documents/IdentifiedChapter.php +++ b/tests/Documents/IdentifiedChapter.php @@ -5,6 +5,7 @@ namespace Documents; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\EmbeddedDocument */ @@ -16,7 +17,11 @@ class IdentifiedChapter /** @ODM\Field(type="string") */ public $name; - /** @ODM\EmbedMany(targetDocument=Page::class) */ + /** + * @ODM\EmbedMany(targetDocument=Page::class) + * + * @var Collection + */ public $pages; public function __construct($name = null) diff --git a/tests/Documents/Project.php b/tests/Documents/Project.php index a019879e96..374e0ece5a 100644 --- a/tests/Documents/Project.php +++ b/tests/Documents/Project.php @@ -22,16 +22,27 @@ class Project /** @ODM\Field(type="string") */ private $name; - /** @ODM\EmbedOne(targetDocument=Address::class) */ + /** + * @ODM\EmbedOne(targetDocument=Address::class) + * + * @var Address|null + */ private $address; - /** @ODM\ReferenceMany(targetDocument=SubProject::class, cascade="all") */ + /** + * @ODM\ReferenceMany(targetDocument=SubProject::class, cascade="all") + * + * @var Collection + */ private $subProjects; - public function __construct($name, ?Collection $subProjects = null) + /** + * @param Collection|null $subProjects + */ + public function __construct(string $name, ?Collection $subProjects = null) { $this->name = $name; - $this->subProjects = $subProjects ? $subProjects : new ArrayCollection(); + $this->subProjects = $subProjects ?? new ArrayCollection(); } public function getId() @@ -59,11 +70,17 @@ public function getAddress() return $this->address; } + /** + * @param Collection $subProjects + */ public function setSubProjects(Collection $subProjects) { $this->subProjects = $subProjects; } + /** + * @return Collection + */ public function getSubProjects() { return $this->subProjects; diff --git a/tests/Documents/SubProject.php b/tests/Documents/SubProject.php index 847542cbfb..f45f9fe114 100644 --- a/tests/Documents/SubProject.php +++ b/tests/Documents/SubProject.php @@ -10,14 +10,24 @@ /** @ODM\Document */ class SubProject extends Project { - /** @ODM\EmbedMany(targetDocument=Issue::class) */ + /** + * @ODM\EmbedMany(targetDocument=Issue::class) + * + * @var Collection + */ private $issues; + /** + * @return Collection + */ public function getIssues() { return $this->issues; } + /** + * @param Collection $issues + */ public function setIssues(Collection $issues) { $this->issues = $issues;