mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 20:47:28 +00:00
Tweak code
This commit is contained in:
@@ -41,7 +41,7 @@ class BlockNode extends Node
|
||||
|
||||
if (!$this->getNode('body') instanceof NodeOutputInterface && $compiler->getEnvironment()->useYield()) {
|
||||
// needed when body doesn't yield anything
|
||||
$compiler->write("yield;\n");
|
||||
$compiler->write("yield '';\n");
|
||||
}
|
||||
|
||||
$compiler
|
||||
|
||||
@@ -344,7 +344,7 @@ final class ModuleNode extends Node
|
||||
}
|
||||
} elseif ($compiler->getEnvironment()->useYield() && !$this->hasNodeOutputNodes($this->getNode('body'))) {
|
||||
// ensure at least one yield call even for templates with no output
|
||||
$compiler->write("yield;\n");
|
||||
$compiler->write("yield '';\n");
|
||||
}
|
||||
|
||||
$compiler
|
||||
|
||||
+12
-12
@@ -33,17 +33,6 @@ class BlockTest extends NodeTestCase
|
||||
{
|
||||
$tests = [];
|
||||
|
||||
$tests[] = [new BlockNode('foo', new TextNode('foo', 1), 1), <<<EOF
|
||||
// line 1
|
||||
public function block_foo(\$context, array \$blocks = [])
|
||||
{
|
||||
\$macros = \$this->macros;
|
||||
yield "foo";
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader(), ['use_yield' => true])
|
||||
];
|
||||
|
||||
if (!$this->getEnvironment()->useYield()) {
|
||||
$tests[] = [new BlockNode('foo', new TextNode('foo', 1), 1), <<<EOF
|
||||
// line 1
|
||||
@@ -56,12 +45,23 @@ EOF
|
||||
, new Environment(new ArrayLoader())
|
||||
];
|
||||
} else {
|
||||
$tests[] = [new BlockNode('foo', new TextNode('foo', 1), 1), <<<EOF
|
||||
// line 1
|
||||
public function block_foo(\$context, array \$blocks = [])
|
||||
{
|
||||
\$macros = \$this->macros;
|
||||
yield "foo";
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader())
|
||||
];
|
||||
|
||||
$tests[] = [new BlockNode('foo', new Node(), 1), <<<EOF
|
||||
// line 1
|
||||
public function block_foo(\$context, array \$blocks = [])
|
||||
{
|
||||
\$macros = \$this->macros;
|
||||
yield;
|
||||
yield '';
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader())
|
||||
|
||||
@@ -58,14 +58,19 @@ class TemplateWrapperTest extends TestCase
|
||||
{
|
||||
$twig = new Environment(new ArrayLoader([
|
||||
'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}',
|
||||
], ['use_yield' => false]));
|
||||
$twig->addGlobal('bar', 'BAR');
|
||||
]));
|
||||
|
||||
$wrapper = $twig->load('index');
|
||||
if (!$twig->useYield()) {
|
||||
$twig->addGlobal('bar', 'BAR');
|
||||
|
||||
ob_start();
|
||||
$wrapper->displayBlock('foo', ['foo' => 'FOO']);
|
||||
$wrapper = $twig->load('index');
|
||||
|
||||
$this->assertEquals('FOOBAR', ob_get_clean());
|
||||
ob_start();
|
||||
$wrapper->displayBlock('foo', ['foo' => 'FOO']);
|
||||
|
||||
$this->assertEquals('FOOBAR', ob_get_clean());
|
||||
} else {
|
||||
$this->markTestSkipped('yield not used.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user