assertEquals($body, $node->getNode('body')); $this->assertEquals($blocks, $node->getNode('blocks')); $this->assertEquals($macros, $node->getNode('macros')); $this->assertEquals($parent, $node->getNode('parent')); $this->assertEquals($source->getName(), $node->getTemplateName()); } public function getTests() { $twig = new Environment(new ArrayLoader(['foo.twig' => '{{ foo }}'])); $tests = []; $body = new BodyNode([new TextNode('foo', 1)]); $extends = null; $blocks = new Node(); $macros = new Node(); $traits = new Node(); $source = new Source('{{ foo }}', 'foo.twig'); $node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source); $tests[] = [$node, << */ private array \$macros = []; public function __construct(Environment \$env) { parent::__construct(\$env); \$this->source = \$this->getSourceContext(); \$this->parent = false; \$this->blocks = [ ]; } protected function doDisplay(array \$context, array \$blocks = []): iterable { \$macros = \$this->macros; // line 1 yield "foo"; return; yield ''; } /** * @codeCoverageIgnore */ public function getTemplateName(): string { return "foo.twig"; } /** * @codeCoverageIgnore */ public function getDebugInfo(): array { return array ( 42 => 1,); } public function getSourceContext(): Source { return new Source("", "foo.twig", ""); } } EOF , $twig, true]; $import = new ImportNode(new ConstantExpression('foo.twig', 1), new AssignNameExpression('macro', 1), 2); $body = new BodyNode([$import]); $extends = new ConstantExpression('layout.twig', 1); $node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source); $tests[] = [$node, << */ private array \$macros = []; public function __construct(Environment \$env) { parent::__construct(\$env); \$this->source = \$this->getSourceContext(); \$this->blocks = [ ]; } protected function doGetParent(array \$context): bool|string|Template|TemplateWrapper { // line 1 return "layout.twig"; } protected function doDisplay(array \$context, array \$blocks = []): iterable { \$macros = \$this->macros; // line 2 \$macros["macro"] = \$this->macros["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2)->unwrap(); // line 1 \$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1); yield from \$this->parent->unwrap()->yield(\$context, array_merge(\$this->blocks, \$blocks)); } /** * @codeCoverageIgnore */ public function getTemplateName(): string { return "foo.twig"; } /** * @codeCoverageIgnore */ public function isTraitable(): bool { return false; } /** * @codeCoverageIgnore */ public function getDebugInfo(): array { return array ( 48 => 1, 46 => 2, 39 => 1,); } public function getSourceContext(): Source { return new Source("", "foo.twig", ""); } } EOF , $twig, true]; $set = new SetNode(false, new Node([new AssignNameExpression('foo', 4)]), new Node([new ConstantExpression('foo', 4)]), 4); $body = new BodyNode([$set]); $extends = new ConditionalExpression( new ConstantExpression(true, 2), new ConstantExpression('foo', 2), new ConstantExpression('foo', 2), 2 ); $twig = new Environment(new ArrayLoader(['foo.twig' => '{{ foo }}']), ['debug' => true]); $node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source); $tests[] = [$node, << */ private array \$macros = []; public function __construct(Environment \$env) { parent::__construct(\$env); \$this->source = \$this->getSourceContext(); \$this->blocks = [ ]; } protected function doGetParent(array \$context): bool|string|Template|TemplateWrapper { // line 2 return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2); } protected function doDisplay(array \$context, array \$blocks = []): iterable { \$macros = \$this->macros; // line 4 \$context["foo"] = "foo"; // line 2 yield from \$this->getParent(\$context)->unwrap()->yield(\$context, array_merge(\$this->blocks, \$blocks)); } /** * @codeCoverageIgnore */ public function getTemplateName(): string { return "foo.twig"; } /** * @codeCoverageIgnore */ public function isTraitable(): bool { return false; } /** * @codeCoverageIgnore */ public function getDebugInfo(): array { return array ( 48 => 2, 46 => 4, 39 => 2,); } public function getSourceContext(): Source { return new Source("{{ foo }}", "foo.twig", ""); } } EOF , $twig, true]; return $tests; } }