File tree Expand file tree Collapse file tree 8 files changed +75
-14
lines changed
Doctrine/ODM/MongoDB/Tests/Functional Expand file tree Collapse file tree 8 files changed +75
-14
lines changed Original file line number Diff line number Diff line change @@ -453,6 +453,7 @@ public function testReplacementOfEmbedManyElements()
453
453
$ firstChapter ->name = 'First chapter A ' ;
454
454
455
455
// Developers commonly attempt to replace the contents of an EmbedMany with a new ArrayCollection like this:
456
+ /** @var ArrayCollection<int, Chapter> $replacementChapters */
456
457
$ replacementChapters = new ArrayCollection ();
457
458
$ replacementChapters ->add ($ firstChapter );
458
459
$ replacementChapters ->add (new Chapter ('Second chapter B ' ));
@@ -478,9 +479,10 @@ public function testReplacementOfIdentifiedEmbedManyElements()
478
479
$ this ->dm ->flush ();
479
480
$ this ->dm ->clear ();
480
481
481
- $ book = $ this ->dm ->getRepository (Book::CLASSNAME )->findOneBy (['_id ' => $ book ->id ]);
482
- $ firstChapter = $ book ->identifiedChapters ->first ();
483
- $ firstChapter ->name = 'First chapter A ' ;
482
+ $ book = $ this ->dm ->getRepository (Book::CLASSNAME )->findOneBy (['_id ' => $ book ->id ]);
483
+ $ firstChapter = $ book ->identifiedChapters ->first ();
484
+ $ firstChapter ->name = 'First chapter A ' ;
485
+ /** @var ArrayCollection<int, IdentifiedChapter> $replacementChapters */
484
486
$ replacementChapters = new ArrayCollection ();
485
487
$ replacementChapters ->add ($ firstChapter );
486
488
$ replacementChapters ->add (new IdentifiedChapter ('Second chapter B ' ));
Original file line number Diff line number Diff line change 5
5
namespace Doctrine \ODM \MongoDB \Tests \Functional ;
6
6
7
7
use Doctrine \Common \Collections \ArrayCollection ;
8
+ use Doctrine \Common \Collections \Collection ;
8
9
use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
9
10
use Doctrine \ODM \MongoDB \PersistentCollection ;
10
11
use Doctrine \ODM \MongoDB \Tests \BaseTest ;
@@ -560,6 +561,8 @@ public function testWhenCopyingManyEmbedSubDocumentsFromOneDocumentToAnotherWill
560
561
$ this ->dm ->persist ($ test1 );
561
562
$ this ->dm ->flush ();
562
563
564
+ assert ($ test1 ->embedMany instanceof Collection);
565
+
563
566
$ test2 = new ChangeEmbeddedIdTest ();
564
567
$ test2 ->embedMany = $ test1 ->embedMany ; //using clone will work
565
568
$ this ->dm ->persist ($ test2 );
@@ -642,10 +645,18 @@ class ChangeEmbeddedIdTest
642
645
/** @ODM\Id */
643
646
public $ id ;
644
647
645
- /** @ODM\EmbedOne(targetDocument=EmbeddedDocumentWithId::class) */
648
+ /**
649
+ * @ODM\EmbedOne(targetDocument=EmbeddedDocumentWithId::class)
650
+ *
651
+ * @var EmbeddedDocumentWithId|null
652
+ */
646
653
public $ embed ;
647
654
648
- /** @ODM\EmbedMany(targetDocument=EmbeddedDocumentWithId::class) */
655
+ /**
656
+ * @ODM\EmbedMany(targetDocument=EmbeddedDocumentWithId::class)
657
+ *
658
+ * @var Collection<int, EmbeddedDocumentWithId>|array<EmbeddedDocumentWithId>
659
+ */
649
660
public $ embedMany ;
650
661
651
662
public function __construct ()
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ public function testSavesEmbeddedDocumentsInReferencedDocument()
22
22
23
23
$ project = $ this ->dm ->find (Project::class, $ project ->getId ());
24
24
25
+ /** @var ArrayCollection<int, SubProject> $subProjects */
25
26
$ subProjects = new ArrayCollection ();
26
27
$ subProject1 = new SubProject ('Sub Project #1 ' );
27
28
$ subProject2 = new SubProject ('Sub Project #2 ' );
Original file line number Diff line number Diff line change 5
5
namespace Doctrine \ODM \MongoDB \Tests \Functional \Ticket ;
6
6
7
7
use Doctrine \Common \Collections \ArrayCollection ;
8
+ use Doctrine \Common \Collections \Collection ;
8
9
use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
9
10
use Doctrine \ODM \MongoDB \PersistentCollection \PersistentCollectionInterface ;
10
11
use Doctrine \ODM \MongoDB \Tests \BaseTest ;
@@ -20,6 +21,7 @@ public function testClearCollection()
20
21
$ doc ->embeds ->clear ();
21
22
$ doc ->embeds ->add (new GH1011Embedded ('test2 ' ));
22
23
$ this ->uow ->computeChangeSets ();
24
+ $ this ->assertInstanceOf (PersistentCollectionInterface::class, $ doc ->embeds );
23
25
$ this ->assertTrue ($ this ->uow ->isCollectionScheduledForUpdate ($ doc ->embeds ));
24
26
$ this ->assertFalse ($ this ->uow ->isCollectionScheduledForDeletion ($ doc ->embeds ));
25
27
}
@@ -47,7 +49,11 @@ class GH1011Document
47
49
/** @ODM\Id */
48
50
public $ id ;
49
51
50
- /** @ODM\EmbedMany(targetDocument=GH1011Embedded::class, strategy="set") */
52
+ /**
53
+ * @ODM\EmbedMany(targetDocument=GH1011Embedded::class, strategy="set")
54
+ *
55
+ * @var Collection<int, GH1011Embedded>
56
+ */
51
57
public $ embeds ;
52
58
53
59
public function __construct ()
Original file line number Diff line number Diff line change 5
5
namespace Documents ;
6
6
7
7
use Doctrine \Common \Collections \ArrayCollection ;
8
+ use Doctrine \Common \Collections \Collection ;
8
9
use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
9
10
10
11
/** @ODM\Document */
@@ -18,10 +19,18 @@ class Book
18
19
/** @ODM\Field(type="int") @ODM\Version */
19
20
public $ version = 1 ;
20
21
21
- /** @ODM\EmbedMany(targetDocument=Chapter::class, strategy="atomicSet") */
22
+ /**
23
+ * @ODM\EmbedMany(targetDocument=Chapter::class, strategy="atomicSet")
24
+ *
25
+ * @var Collection<int, Chapter>
26
+ */
22
27
public $ chapters ;
23
28
24
- /** @ODM\EmbedMany(targetDocument=IdentifiedChapter::class, strategy="atomicSet") */
29
+ /**
30
+ * @ODM\EmbedMany(targetDocument=IdentifiedChapter::class, strategy="atomicSet")
31
+ *
32
+ * @var Collection<int, IdentifiedChapter>
33
+ */
25
34
public $ identifiedChapters ;
26
35
27
36
public function __construct ()
Original file line number Diff line number Diff line change 5
5
namespace Documents ;
6
6
7
7
use Doctrine \Common \Collections \ArrayCollection ;
8
+ use Doctrine \Common \Collections \Collection ;
8
9
use Doctrine \ODM \MongoDB \Mapping \Annotations as ODM ;
9
10
10
11
/** @ODM\EmbeddedDocument */
@@ -16,7 +17,11 @@ class IdentifiedChapter
16
17
/** @ODM\Field(type="string") */
17
18
public $ name ;
18
19
19
- /** @ODM\EmbedMany(targetDocument=Page::class) */
20
+ /**
21
+ * @ODM\EmbedMany(targetDocument=Page::class)
22
+ *
23
+ * @var Collection<int, Page>
24
+ */
20
25
public $ pages ;
21
26
22
27
public function __construct ($ name = null )
Original file line number Diff line number Diff line change @@ -22,16 +22,27 @@ class Project
22
22
/** @ODM\Field(type="string") */
23
23
private $ name ;
24
24
25
- /** @ODM\EmbedOne(targetDocument=Address::class) */
25
+ /**
26
+ * @ODM\EmbedOne(targetDocument=Address::class)
27
+ *
28
+ * @var Address|null
29
+ */
26
30
private $ address ;
27
31
28
- /** @ODM\ReferenceMany(targetDocument=SubProject::class, cascade="all") */
32
+ /**
33
+ * @ODM\ReferenceMany(targetDocument=SubProject::class, cascade="all")
34
+ *
35
+ * @var Collection<int, SubProject>
36
+ */
29
37
private $ subProjects ;
30
38
31
- public function __construct ($ name , ?Collection $ subProjects = null )
39
+ /**
40
+ * @param Collection<int, SubProject>|null $subProjects
41
+ */
42
+ public function __construct (string $ name , ?Collection $ subProjects = null )
32
43
{
33
44
$ this ->name = $ name ;
34
- $ this ->subProjects = $ subProjects ? $ subProjects : new ArrayCollection ();
45
+ $ this ->subProjects = $ subProjects ?? new ArrayCollection ();
35
46
}
36
47
37
48
public function getId ()
@@ -59,11 +70,17 @@ public function getAddress()
59
70
return $ this ->address ;
60
71
}
61
72
73
+ /**
74
+ * @param Collection<int, SubProject> $subProjects
75
+ */
62
76
public function setSubProjects (Collection $ subProjects )
63
77
{
64
78
$ this ->subProjects = $ subProjects ;
65
79
}
66
80
81
+ /**
82
+ * @return Collection<int, SubProject>
83
+ */
67
84
public function getSubProjects ()
68
85
{
69
86
return $ this ->subProjects ;
Original file line number Diff line number Diff line change 10
10
/** @ODM\Document */
11
11
class SubProject extends Project
12
12
{
13
- /** @ODM\EmbedMany(targetDocument=Issue::class) */
13
+ /**
14
+ * @ODM\EmbedMany(targetDocument=Issue::class)
15
+ *
16
+ * @var Collection<int, Issue>
17
+ */
14
18
private $ issues ;
15
19
20
+ /**
21
+ * @return Collection<int, Issue>
22
+ */
16
23
public function getIssues ()
17
24
{
18
25
return $ this ->issues ;
19
26
}
20
27
28
+ /**
29
+ * @param Collection<int, Issue> $issues
30
+ */
21
31
public function setIssues (Collection $ issues )
22
32
{
23
33
$ this ->issues = $ issues ;
You can’t perform that action at this time.
0 commit comments