@@ -51,10 +51,11 @@ public function parentChildrenRelation(): void
51
51
$ parent = new AssetCollection ('parent ' );
52
52
53
53
$ child1 ->setParent ($ parent );
54
- $ parent -> addChild ( $ child2 );
54
+ $ child2 -> setParent ( $ parent );
55
55
56
56
$ this ->assetCollectionRepository ->add ($ parent );
57
57
$ this ->assetCollectionRepository ->add ($ child1 );
58
+ $ this ->assetCollectionRepository ->add ($ child2 );
58
59
59
60
$ this ->persistenceManager ->persistAll ();
60
61
$ this ->persistenceManager ->clearState ();
@@ -65,7 +66,7 @@ public function parentChildrenRelation(): void
65
66
self ::assertEquals ('parent ' , $ persistedParent ->getTitle ());
66
67
self ::assertNull ($ persistedParent ->getParent ());
67
68
68
- $ children = $ persistedParent -> getChildren ( );
69
+ $ children = $ this -> assetCollectionRepository -> findByParent ( $ parent );
69
70
self ::assertEquals (2 , $ children ->count ());
70
71
self ::assertEquals ('child1 ' , $ children ->offsetGet (0 )->getTitle ());
71
72
self ::assertEquals ('child2 ' , $ children ->offsetGet (1 )->getTitle ());
@@ -87,69 +88,6 @@ public function circularParentChildrenRelationThrowsErrorWhenSettingParent(): vo
87
88
$ parent ->setParent ($ childOfChild );
88
89
}
89
90
90
- /**
91
- * @test
92
- */
93
- public function circularParentChildrenRelationThrowsErrorWhenAddingChild (): void
94
- {
95
- $ child = new AssetCollection ('child ' );
96
- $ childOfChild = new AssetCollection ('childOfChild ' );
97
- $ parent = new AssetCollection ('parent ' );
98
-
99
- $ parent ->addChild ($ child );
100
- $ child ->addChild ($ childOfChild );
101
-
102
- $ this ->expectException (\InvalidArgumentException::class);
103
- $ childOfChild ->addChild ($ parent );
104
- }
105
-
106
- /**
107
- * @test
108
- */
109
- public function circularParentChildrenRelationThrowsErrorWhenSettingChildren (): void
110
- {
111
- $ child = new AssetCollection ('child ' );
112
- $ childOfChild = new AssetCollection ('childOfChild ' );
113
- $ parent = new AssetCollection ('parent ' );
114
-
115
- $ parent ->setChildren (new ArrayCollection ([$ child ]));
116
- $ child ->setChildren (new ArrayCollection ([$ childOfChild ]));
117
-
118
- $ this ->expectException (\InvalidArgumentException::class);
119
- $ childOfChild ->setChildren (new ArrayCollection ([$ parent ]));
120
- }
121
-
122
- /**
123
- * @test
124
- */
125
- public function removingTheChildDeletesIt (): void
126
- {
127
- $ child = new AssetCollection ('child ' );
128
- $ parent = new AssetCollection ('parent ' );
129
-
130
- $ child ->setParent ($ parent );
131
-
132
- $ this ->assetCollectionRepository ->add ($ parent );
133
- $ this ->assetCollectionRepository ->add ($ child );
134
-
135
- $ this ->persistenceManager ->persistAll ();
136
- $ this ->persistenceManager ->clearState ();
137
-
138
- $ persistedChild = $ this ->assetCollectionRepository ->findOneByTitle ('child ' );
139
- $ persistedParent = $ this ->assetCollectionRepository ->findOneByTitle ('parent ' );
140
-
141
- $ persistedParent ->removeChild ($ persistedChild );
142
-
143
- $ this ->persistenceManager ->persistAll ();
144
- $ this ->persistenceManager ->clearState ();
145
-
146
- $ persistedChild = $ this ->assetCollectionRepository ->findOneByTitle ('child ' );
147
- $ persistedParent = $ this ->assetCollectionRepository ->findOneByTitle ('parent ' );
148
-
149
- self ::assertNull ($ persistedChild );
150
- self ::assertEquals (0 , $ persistedParent ->getChildren ()->count ());
151
- }
152
-
153
91
/**
154
92
* @test
155
93
*/
@@ -176,8 +114,10 @@ public function unsettingTheParentRemovesChildFromParent(): void
176
114
$ persistedChild = $ this ->assetCollectionRepository ->findOneByTitle ('child ' );
177
115
$ persistedParent = $ this ->assetCollectionRepository ->findOneByTitle ('parent ' );
178
116
117
+ $ children = $ this ->assetCollectionRepository ->findByParent ($ persistedParent );
118
+
179
119
self ::assertNull ($ persistedChild ->getParent ());
180
- self ::assertEquals (0 , $ persistedParent -> getChildren ()-> count ());
120
+ self ::assertEquals (0 , count ($ children ));
181
121
}
182
122
183
123
/**
@@ -208,29 +148,4 @@ public function deletingTheParentDeletesTheChild(): void
208
148
self ::assertNull ($ persistedChild );
209
149
self ::assertNull ($ persistedParent );
210
150
}
211
-
212
- /**
213
- * @test
214
- */
215
- public function settingChildrenSetsTheirParent (): void
216
- {
217
- $ child1 = new AssetCollection ('child1 ' );
218
- $ child2 = new AssetCollection ('child2 ' );
219
- $ parent = new AssetCollection ('parent ' );
220
-
221
- $ parent ->setChildren (new ArrayCollection ([$ child1 , $ child2 ]));
222
-
223
- $ this ->assetCollectionRepository ->add ($ parent );
224
- $ this ->assetCollectionRepository ->add ($ child1 );
225
- $ this ->assetCollectionRepository ->add ($ child2 );
226
-
227
- $ this ->persistenceManager ->persistAll ();
228
- $ this ->persistenceManager ->clearState ();
229
-
230
- $ persistedChild1 = $ this ->assetCollectionRepository ->findOneByTitle ('child1 ' );
231
- $ persistedChild2 = $ this ->assetCollectionRepository ->findOneByTitle ('child2 ' );
232
-
233
- self ::assertEquals ('parent ' , $ persistedChild1 ->getParent ()->getTitle ());
234
- self ::assertEquals ('parent ' , $ persistedChild2 ->getParent ()->getTitle ());
235
- }
236
151
}
0 commit comments