Merge branch '2.x' into 3.x

* 2.x:
  fixed macro auto-import when a template contains only macros
  fixed end of constructor node logic
  bumped version to 2.11.3-DEV
  prepared the 2.11.2 release
  fixed macro auto-import
  fix CS
  fix CS
  bumped version to 2.12
This commit is contained in:
Fabien Potencier
2019-06-08 09:01:50 +02:00
6 changed files with 41 additions and 22 deletions
+6 -2
View File
@@ -17,9 +17,13 @@
* bumped minimum PHP version to 7.2
* removed PSR-0 classes
* 2.11.2 (2019-XX-XX)
* 2.11.3 (2019-XX-XX)
* n/a
* fixed macro auto-import when a template contains only macros
* 2.11.2 (2019-06-05)
* fixed macro auto-import
* 2.11.1 (2019-06-04)
@@ -33,6 +33,7 @@ final class MacroAutoImportNodeVisitor implements NodeVisitorInterface
{
if ($node instanceof ModuleNode) {
$this->inAModule = true;
$this->hasMacroCalls = false;
}
return $node;
@@ -43,11 +44,7 @@ final class MacroAutoImportNodeVisitor implements NodeVisitorInterface
if ($node instanceof ModuleNode) {
$this->inAModule = false;
if ($this->hasMacroCalls) {
$body = [new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, 'import', true)];
foreach ($node->getNode('body') as $n) {
$body[] = $n;
}
$node->setNode('body', new Node($body));
$node->getNode('constructor_end')->setNode('_auto_macro_import', new ImportNode(new NameExpression('_self', 0), new AssignNameExpression('_self', 0), 0, 'import', true));
}
} elseif ($this->inAModule) {
if (
+1 -1
View File
@@ -99,7 +99,7 @@ final class SandboxNodeVisitor implements NodeVisitorInterface
if ($node instanceof ModuleNode) {
$this->inAModule = false;
$node->setNode('constructor_end', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')]));
$node->getNode('constructor_end')->setNode('_security_check', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')]));
} elseif ($this->inAModule) {
if ($node instanceof PrintNode || $node instanceof SetNode) {
$this->needsToStringWrap = false;
+12 -12
View File
@@ -54,7 +54,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
public function testGlobals()
{
$loader = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Source('', '')));
$loader->expects($this->any())->method('getSourceContext')->willReturn(new Source('', ''));
// globals can be added after calling getGlobals
$twig = new Environment($loader);
@@ -188,10 +188,10 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
// skipped.
$cache->expects($this->once())
->method('generateKey')
->will($this->returnValue('key'));
->willReturn('key');
$cache->expects($this->once())
->method('getTimestamp')
->will($this->returnValue(0));
->willReturn(0);
$loader->expects($this->never())
->method('isFresh');
$cache->expects($this->once())
@@ -217,13 +217,13 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
// the loader returns true for isFresh().
$cache->expects($this->once())
->method('generateKey')
->will($this->returnValue('key'));
->willReturn('key');
$cache->expects($this->once())
->method('getTimestamp')
->will($this->returnValue($now));
->willReturn($now);
$loader->expects($this->once())
->method('isFresh')
->will($this->returnValue(true));
->willReturn(true);
$cache->expects($this->atLeastOnce())
->method('load');
@@ -243,13 +243,13 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
$cache->expects($this->once())
->method('generateKey')
->will($this->returnValue('key'));
->willReturn('key');
$cache->expects($this->once())
->method('getTimestamp')
->will($this->returnValue($now));
->willReturn($now);
$loader->expects($this->once())
->method('isFresh')
->will($this->returnValue(false));
->willReturn(false);
$cache->expects($this->once())
->method('write');
$cache->expects($this->once())
@@ -319,7 +319,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
public function testAddRuntimeLoader()
{
$runtimeLoader = $this->getMockBuilder(RuntimeLoaderInterface::class)->getMock();
$runtimeLoader->expects($this->any())->method('load')->will($this->returnValue(new Twig_Tests_EnvironmentTest_Runtime()));
$runtimeLoader->expects($this->any())->method('load')->willReturn(new Twig_Tests_EnvironmentTest_Runtime());
$loader = new ArrayLoader([
'func_array' => '{{ from_runtime_array("foo") }}',
@@ -359,11 +359,11 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase
$loader->expects($this->any())
->method('getSourceContext')
->with($templateName)
->will($this->returnValue(new Source($templateContent, $templateName)));
->willReturn(new Source($templateContent, $templateName));
$loader->expects($this->any())
->method('getCacheKey')
->with($templateName)
->will($this->returnValue($templateName));
->willReturn($templateName);
return $loader;
}
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% import 'macros' as macro %}
{{ macro.foo() }}
--TEMPLATE(macros)--
{% macro foo() %}
foo
{{- _self.bar() }}
{% endmacro %}
{% macro bar() -%}
bar
{% endmacro %}
--DATA--
return []
--EXPECT--
foobar
+2 -2
View File
@@ -79,11 +79,11 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase
public function testExists()
{
$loader1 = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loader1->expects($this->once())->method('exists')->will($this->returnValue(false));
$loader1->expects($this->once())->method('exists')->willReturn(false);
$loader1->expects($this->never())->method('getSourceContext');
$loader2 = $this->getMockBuilder(LoaderInterface::class)->getMock();
$loader2->expects($this->once())->method('exists')->will($this->returnValue(true));
$loader2->expects($this->once())->method('exists')->willReturn(true);
$loader2->expects($this->never())->method('getSourceContext');
$loader = new ChainLoader();