File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed
Tests/Functional/Domain/Model Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -198,11 +198,13 @@ public function getParent(): ?self
198
198
private function validateCircularHierarchy (): void
199
199
{
200
200
$ parent = $ this ->parent ;
201
- $ parents = [$ parent ];
202
201
while ($ parent !== null ) {
203
202
$ parent = $ parent ->getParent ();
204
- if (in_array ($ parent , $ parents , true )) {
205
- throw new \InvalidArgumentException ('Circular reference detected ' , 1680328041 );
203
+ if ($ parent === $ this ->parent ) {
204
+ throw new \InvalidArgumentException (sprintf (
205
+ 'Circular reference detected, parent AssetCollection "%s" appeared twice in the hierarchy ' ,
206
+ $ parent ->getTitle ()
207
+ ), 1680328041 );
206
208
}
207
209
}
208
210
}
Original file line number Diff line number Diff line change @@ -73,19 +73,22 @@ public function parentChildrenRelation(): void
73
73
}
74
74
75
75
/**
76
+ * Verifies the following hierarchie throws an error:
77
+ * first -> second -> third -> first
78
+ *
76
79
* @test
77
80
*/
78
81
public function circularParentChildrenRelationThrowsErrorWhenSettingParent (): void
79
82
{
80
- $ child = new AssetCollection ('child ' );
81
- $ childOfChild = new AssetCollection ('childOfChild ' );
82
- $ parent = new AssetCollection ('parent ' );
83
+ $ firstCollection = new AssetCollection ('first ' );
84
+ $ secondCollection = new AssetCollection ('second ' );
85
+ $ thirdCollection = new AssetCollection ('third ' );
83
86
84
- $ child ->setParent ($ parent );
85
- $ childOfChild ->setParent ($ child );
87
+ $ secondCollection ->setParent ($ firstCollection );
88
+ $ thirdCollection ->setParent ($ secondCollection );
86
89
87
90
$ this ->expectException (\InvalidArgumentException::class);
88
- $ parent ->setParent ($ childOfChild );
91
+ $ firstCollection ->setParent ($ thirdCollection );
89
92
}
90
93
91
94
/**
You can’t perform that action at this time.
0 commit comments