@@ -50,11 +50,45 @@ public function testRemoveChild()
50
50
$ i ++;
51
51
}
52
52
53
- $ this ->expectException (Exception::class);
53
+ // Check all children have correct parent
54
+ foreach ($ object ->getChildren () as $ child ) {
55
+ self ::assertEquals ($ child ->getParent (), $ object );
56
+ }
54
57
58
+ $ this ->expectException (Exception::class);
55
59
$ object ->removeChild ($ unknownChild );
56
60
}
57
61
62
+ public function testReplacedChildParent () {
63
+
64
+ $ childToReplace = Integer::create (1 );
65
+ $ replacement = Integer::create (0 );
66
+
67
+ $ object = Sequence::create ([
68
+ NullObject::create (),
69
+ $ childToReplace ,
70
+ NullObject::create (),
71
+ ]);
72
+
73
+ $ expectedObject = Sequence::create ([
74
+ NullObject::create (),
75
+ $ replacement ,
76
+ NullObject::create (),
77
+ ]);
78
+
79
+ $ expectedBinary = $ expectedObject ->getBinary ();
80
+
81
+ $ object ->replaceChild ($ childToReplace , $ replacement );
82
+
83
+ // Check binary data as expected after tree rebuild
84
+ self ::assertEquals ($ expectedObject ->getBinary (), $ expectedBinary );
85
+
86
+ // Check all children have correct parent
87
+ foreach ($ object ->getChildren () as $ child ) {
88
+ self ::assertEquals ($ child ->getParent (), $ object );
89
+ }
90
+ }
91
+
58
92
public function testReplaceChild ()
59
93
{
60
94
$ unknownChild = Integer::create (0 );
@@ -72,7 +106,9 @@ public function testReplaceChild()
72
106
$ object ->replaceChild ($ childToReplace , $ replacement );
73
107
74
108
// New child now NullObject instead of Sequence
75
- self ::assertInstanceOf (NullObject::class, $ object ->getChildren ()[0 ]);
109
+ foreach ($ object ->getChildren () as $ child ) {
110
+ self ::assertInstanceOf (NullObject::class, $ child );
111
+ }
76
112
77
113
// We still have 1 child
78
114
self ::assertCount (3 , $ object ->getChildren ());
@@ -85,6 +121,11 @@ public function testReplaceChild()
85
121
$ i ++;
86
122
}
87
123
124
+ // Check all children have correct parent
125
+ foreach ($ object ->getChildren () as $ child ) {
126
+ self ::assertEquals ($ child ->getParent (), $ object );
127
+ }
128
+
88
129
// Exception if we trying replace unknown child
89
130
$ this ->expectException (Exception::class);
90
131
$ object ->replaceChild ($ unknownChild , $ replacement );
@@ -128,5 +169,10 @@ public function testAppendChild()
128
169
self ::assertEquals ($ i , $ index );
129
170
$ i ++;
130
171
}
172
+
173
+ // Check all children have correct parent
174
+ foreach ($ object ->getChildren () as $ child ) {
175
+ self ::assertEquals ($ child ->getParent (), $ object );
176
+ }
131
177
}
132
178
}
0 commit comments