mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-06 07:27:17 +00:00
Fix dumping callables on Node::__toString()
This commit is contained in:
+1
-1
@@ -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)];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user