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
5858 public function addChild (self |string |callable $ node ): self
5959 {
6060 if (\is_string ($ node )) {
61- $ node = new self ($ node, $ this );
61+ $ node = new self ($ node );
6262 }
6363
6464 $ this ->children [] = $ node ;
Original file line number Diff line number Diff line change @@ -195,6 +195,26 @@ public function testRenderNodeWithMultipleChildren()
195195TREE , self ::normalizeLineBreaks (trim ($ output ->fetch ())));
196196 }
197197
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+
198218 public function testRenderTreeWithDuplicateNodeNames ()
199219 {
200220 $ rootNode = new TreeNode ('Root ' );
Original file line number Diff line number Diff line change @@ -34,6 +34,24 @@ public function testAddingChildren()
3434 $ this ->assertSame ($ child , iterator_to_array ($ root ->getChildren ())[0 ]);
3535 }
3636
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+
3755 public function testAddingChildrenWithGenerators ()
3856 {
3957 $ root = new TreeNode ('Root ' );
You can’t perform that action at this time.
0 commit comments