Update Node::__toString() to include the node tag if set

This commit is contained in:
Fabien Potencier
2024-08-24 17:25:12 +02:00
parent 4b99692e2a
commit 157d36ae43
3 changed files with 40 additions and 10 deletions
+26 -2
View File
@@ -28,7 +28,13 @@ class NodeTest extends TestCase
// callable is not a supported type for a Node attribute, but Drupal uses some apparently
$node = new Node([], ['value' => function () { return '1'; }], 1);
$this->assertEquals('Twig\Node\Node(value: \Closure)', (string) $node);
$this->assertEquals(<<<EOF
Twig\Node\Node
attributes:
value: \Closure
EOF
, (string) $node
);
}
public function testToStringWithTwigCallables()
@@ -39,7 +45,25 @@ class NodeTest extends TestCase
'test' => new TwigTest('a_test'),
], 1);
$this->assertEquals('Twig\Node\Node(function: Twig\TwigFunction(a_function), filter: Twig\TwigFilter(a_filter), test: Twig\TwigTest(a_test))', (string) $node);
$this->assertEquals(<<<EOF
Twig\Node\Node
attributes:
function: Twig\TwigFunction(a_function)
filter: Twig\TwigFilter(a_filter)
test: Twig\TwigTest(a_test)
EOF
, (string) $node);
}
public function testToStringWithTag()
{
$node = new Node([], [], 1, 'tag');
$this->assertEquals(<<<EOF
Twig\Node\Node
tag: tag
EOF
, (string) $node);
}
public function testAttributeDeprecationIgnore()