Skip to content

[Console] Fix TreeHelper::addChild when providing a string #61080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 7.3
Choose a base branch
from

Conversation

jtattevin
Copy link

@jtattevin jtattevin commented Jul 9, 2025

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
Issues --
License MIT

When using the tree helper, the method addChild allow to pass a string instead of an instance of TreeNode, for example :

$rootNode = new TreeNode('Root');
$rootNode->addChild('Child 1');
$rootNode->addChild('Child 2');
$rootNode->addChild('Child 3');
$tree = TreeHelper::createTree($output, $rootNode);
$tree->render();

This method was creating the TreeNode from the string and using the parent as the children iterator, leading to an error like LogicException: Cycle detected at node: "Child 1"

This commit remove this second parameter.

@chalasr
Copy link
Member

chalasr commented Jul 9, 2025

ping @smnandre

@smnandre
Copy link
Member

smnandre commented Jul 9, 2025

Oops... I missed that, indeed 😶

PR seems very legit 👍

That said, I think it'd be better to add a new test in TreeNodeTest, since this isn’t really the Helper’s responsibility here..

(and I realize there’s currently no test that simply does $node->addChild('string') in TreeNodeTest ... re 😶 )

@jtattevin
Copy link
Author

I've added the test in TreeNodeTest and also checked that the content is used correctly.

I've kept the test in the helper since it's the visible issue, but I can remove it if it's too redundant.

@OskarStark OskarStark changed the title [Console] Fix TreeHelper::addChild when providing a string [Console] Fix TreeHelper::addChild when providing a string Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy