File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
src/Symfony/Component/Console Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ public function getValue(): string
58
58
public function addChild (self |string |callable $ node ): self
59
59
{
60
60
if (\is_string ($ node )) {
61
- $ node = new self ($ node, $ this );
61
+ $ node = new self ($ node );
62
62
}
63
63
64
64
$ this ->children [] = $ node ;
Original file line number Diff line number Diff line change @@ -195,6 +195,26 @@ public function testRenderNodeWithMultipleChildren()
195
195
TREE , self ::normalizeLineBreaks (trim ($ output ->fetch ())));
196
196
}
197
197
198
+ public function testRenderNodeWithMultipleChildrenWithStringConversion ()
199
+ {
200
+ $ rootNode = new TreeNode ('Root ' );
201
+
202
+ $ rootNode ->addChild ('Child 1 ' );
203
+ $ rootNode ->addChild ('Child 2 ' );
204
+ $ rootNode ->addChild ('Child 3 ' );
205
+
206
+ $ output = new BufferedOutput ();
207
+ $ tree = TreeHelper::createTree ($ output , $ rootNode );
208
+
209
+ $ tree ->render ();
210
+ $ this ->assertSame (<<<TREE
211
+ Root
212
+ ├── Child 1
213
+ ├── Child 2
214
+ └── Child 3
215
+ TREE , self ::normalizeLineBreaks (trim ($ output ->fetch ())));
216
+ }
217
+
198
218
public function testRenderTreeWithDuplicateNodeNames ()
199
219
{
200
220
$ rootNode = new TreeNode ('Root ' );
Original file line number Diff line number Diff line change @@ -34,6 +34,24 @@ public function testAddingChildren()
34
34
$ this ->assertSame ($ child , iterator_to_array ($ root ->getChildren ())[0 ]);
35
35
}
36
36
37
+ public function testAddingChildrenAsString ()
38
+ {
39
+ $ root = new TreeNode ('Root ' );
40
+
41
+ $ root ->addChild ('Child 1 ' );
42
+ $ root ->addChild ('Child 2 ' );
43
+
44
+ $ this ->assertSame (2 , iterator_count ($ root ->getChildren ()));
45
+
46
+ $ children = iterator_to_array ($ root ->getChildren ());
47
+
48
+ $ this ->assertSame (0 , iterator_count ($ children [0 ]->getChildren ()));
49
+ $ this ->assertSame (0 , iterator_count ($ children [1 ]->getChildren ()));
50
+
51
+ $ this ->assertSame ('Child 1 ' , $ children [0 ]->getValue ());
52
+ $ this ->assertSame ('Child 2 ' , $ children [1 ]->getValue ());
53
+ }
54
+
37
55
public function testAddingChildrenWithGenerators ()
38
56
{
39
57
$ root = new TreeNode ('Root ' );
You can’t perform that action at this time.
0 commit comments