function () { return '1'; }], 1); $this->assertEquals('Twig\Node\Node(value: \Closure)', (string) $node); } public function testToStringWithTwigCallables() { $node = new Node([], [ 'function' => new TwigFunction('a_function'), 'filter' => new TwigFilter('a_filter'), '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); } public function testAttributeDeprecationIgnore() { $node = new Node([], ['foo' => false]); $node->deprecateAttribute('foo', new NameDeprecation('foo/bar', '2.0', 'bar')); $this->assertSame(false, $node->getAttribute('foo', false)); } /** * @group legacy */ public function testAttributeDeprecationWithoutAlternative() { $node = new Node([], ['foo' => false]); $node->deprecateAttribute('foo', new NameDeprecation('foo/bar', '2.0')); $this->expectDeprecation('Since foo/bar 2.0: Getting attribute "foo" on a "Twig\Node\Node" class is deprecated.'); $this->assertSame(false, $node->getAttribute('foo')); } /** * @group legacy */ public function testAttributeDeprecationWithAlternative() { $node = new Node([], ['foo' => false]); $node->deprecateAttribute('foo', new NameDeprecation('foo/bar', '2.0', 'bar')); $this->expectDeprecation('Since foo/bar 2.0: Getting attribute "foo" on a "Twig\Node\Node" class is deprecated, get the "bar" attribute instead.'); $this->assertSame(false, $node->getAttribute('foo')); } public function testNodeDeprecationIgnore() { $node = new Node(['foo' => $foo = new Node()], []); $node->deprecateNode('foo', new NameDeprecation('foo/bar', '2.0')); $this->assertSame($foo, $node->getNode('foo', false)); } /** * @group legacy */ public function testNodeDeprecationWithoutAlternative() { $node = new Node(['foo' => $foo = new Node()], []); $node->deprecateNode('foo', new NameDeprecation('foo/bar', '2.0')); $this->expectDeprecation('Since foo/bar 2.0: Getting node "foo" on a "Twig\Node\Node" class is deprecated.'); $this->assertSame($foo, $node->getNode('foo')); } /** * @group legacy */ public function testNodeAttributeDeprecationWithAlternative() { $node = new Node(['foo' => $foo = new Node()], []); $node->deprecateNode('foo', new NameDeprecation('foo/bar', '2.0', 'bar')); $this->expectDeprecation('Since foo/bar 2.0: Getting node "foo" on a "Twig\Node\Node" class is deprecated, get the "bar" node instead.'); $this->assertSame($foo, $node->getNode('foo')); } }