Fix dumping callables on Node::__toString()

This commit is contained in:
Fabien Potencier
2024-08-04 16:28:18 +02:00
parent fa3c341725
commit fc64472145
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ class Node implements \Countable, \IteratorAggregate
{
$attributes = [];
foreach ($this->attributes as $name => $value) {
$attributes[] = \sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true)));
$attributes[] = \sprintf('%s: %s', $name, is_callable($value) ? '\Closure' : str_replace("\n", '', var_export($value, true)));
}
$repr = [static::class.'('.implode(', ', $attributes)];
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace Twig\Tests\Node;
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;
use Twig\Node\Node;
class NodeTest extends TestCase
{
public function testToString()
{
// 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);
}
}