diff --git a/src/TemplateWrapper.php b/src/TemplateWrapper.php index 6dbce0a28..1bd332590 100644 --- a/src/TemplateWrapper.php +++ b/src/TemplateWrapper.php @@ -56,7 +56,7 @@ final class TemplateWrapper { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code - $this->template->display($context, \func_num_args() >= 1 ? func_get_arg(1) : []); + $this->template->display($context, \func_num_args() > 1 ? func_get_arg(1) : []); } /** diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php index 1ee81c69f..d1b633ab9 100644 --- a/src/Test/IntegrationTestCase.php +++ b/src/Test/IntegrationTestCase.php @@ -188,7 +188,7 @@ abstract class IntegrationTestCase extends TestCase $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); try { - $template = $twig->loadTemplate('index.twig'); + $template = $twig->load('index.twig'); } catch (\Exception $e) { if (false !== $exception) { $message = $e->getMessage(); diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php index c20a3c638..52010611a 100644 --- a/test/Twig/Tests/ErrorTest.php +++ b/test/Twig/Tests/ErrorTest.php @@ -50,7 +50,7 @@ EOHTML ]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); - $template = $twig->loadTemplate('index.html'); + $template = $twig->load('index.html'); try { $template->render([]); @@ -78,7 +78,7 @@ EOHTML ]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); - $template = $twig->loadTemplate('index.html'); + $template = $twig->load('index.html'); try { $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); @@ -95,7 +95,7 @@ EOHTML $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); - $template = $twig->loadTemplate('index.html'); + $template = $twig->load('index.html'); try { $template->render([]); @@ -114,7 +114,7 @@ EOHTML $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); - $template = $twig->loadTemplate('index.html'); + $template = $twig->load('index.html'); try { $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); @@ -136,7 +136,7 @@ EOHTML $loader = new ArrayLoader($templates); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); - $template = $twig->loadTemplate('index'); + $template = $twig->load('index'); try { $template->render([]); diff --git a/test/Twig/Tests/Extension/SandboxTest.php b/test/Twig/Tests/Extension/SandboxTest.php index b686ad72d..e554bfbc3 100644 --- a/test/Twig/Tests/Extension/SandboxTest.php +++ b/test/Twig/Tests/Extension/SandboxTest.php @@ -53,20 +53,20 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase public function testSandboxWithInheritance() { $twig = $this->getEnvironment(true, [], self::$templates, ['block']); - $twig->loadTemplate('1_child')->render([]); + $twig->load('1_child')->render([]); } public function testSandboxGloballySet() { $twig = $this->getEnvironment(false, [], self::$templates); - $this->assertEquals('FOO', $twig->loadTemplate('1_basic')->render(self::$params), 'Sandbox does nothing if it is disabled globally'); + $this->assertEquals('FOO', $twig->load('1_basic')->render(self::$params), 'Sandbox does nothing if it is disabled globally'); } public function testSandboxUnallowedMethodAccessor() { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_basic1')->render(self::$params); + $twig->load('1_basic1')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method is called'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); @@ -79,7 +79,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_basic2')->render(self::$params); + $twig->load('1_basic2')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError'); @@ -91,7 +91,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_basic3')->render(self::$params); + $twig->load('1_basic3')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); @@ -103,7 +103,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_basic4')->render(self::$params); + $twig->load('1_basic4')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError'); @@ -116,7 +116,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_basic5')->render(self::$params); + $twig->load('1_basic5')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); @@ -129,7 +129,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_basic6')->render(self::$params); + $twig->load('1_basic6')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); @@ -142,7 +142,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_basic7')->render(self::$params); + $twig->load('1_basic7')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); @@ -154,7 +154,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('1_range_operator')->render(self::$params); + $twig->load('1_range_operator')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); @@ -166,7 +166,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => 'foo']); FooObject::reset(); - $this->assertEquals('foo', $twig->loadTemplate('1_basic1')->render(self::$params), 'Sandbox allow some methods'); + $this->assertEquals('foo', $twig->load('1_basic1')->render(self::$params), 'Sandbox allow some methods'); $this->assertEquals(1, FooObject::$called['foo'], 'Sandbox only calls method once'); } @@ -174,7 +174,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => '__toString']); FooObject::reset(); - $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allow some methods'); + $this->assertEquals('foo', $twig->load('1_basic5')->render(self::$params), 'Sandbox allow some methods'); $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); } @@ -182,38 +182,38 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { $twig = $this->getEnvironment(false, [], self::$templates); FooObject::reset(); - $this->assertEquals('foo', $twig->loadTemplate('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled'); + $this->assertEquals('foo', $twig->load('1_basic5')->render(self::$params), 'Sandbox allows __toString when sandbox disabled'); $this->assertEquals(1, FooObject::$called['__toString'], 'Sandbox only calls method once'); } public function testSandboxAllowFilter() { $twig = $this->getEnvironment(true, [], self::$templates, [], ['upper']); - $this->assertEquals('FABIEN', $twig->loadTemplate('1_basic2')->render(self::$params), 'Sandbox allow some filters'); + $this->assertEquals('FABIEN', $twig->load('1_basic2')->render(self::$params), 'Sandbox allow some filters'); } public function testSandboxAllowTag() { $twig = $this->getEnvironment(true, [], self::$templates, ['if']); - $this->assertEquals('foo', $twig->loadTemplate('1_basic3')->render(self::$params), 'Sandbox allow some tags'); + $this->assertEquals('foo', $twig->load('1_basic3')->render(self::$params), 'Sandbox allow some tags'); } public function testSandboxAllowProperty() { $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], ['FooObject' => 'bar']); - $this->assertEquals('bar', $twig->loadTemplate('1_basic4')->render(self::$params), 'Sandbox allow some properties'); + $this->assertEquals('bar', $twig->load('1_basic4')->render(self::$params), 'Sandbox allow some properties'); } public function testSandboxAllowFunction() { $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], ['cycle']); - $this->assertEquals('bar', $twig->loadTemplate('1_basic7')->render(self::$params), 'Sandbox allow some functions'); + $this->assertEquals('bar', $twig->load('1_basic7')->render(self::$params), 'Sandbox allow some functions'); } public function testSandboxAllowRangeOperator() { $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], ['range']); - $this->assertEquals('1', $twig->loadTemplate('1_range_operator')->render(self::$params), 'Sandbox allow the range operator'); + $this->assertEquals('1', $twig->load('1_range_operator')->render(self::$params), 'Sandbox allow the range operator'); } public function testSandboxAllowFunctionsCaseInsensitive() @@ -221,10 +221,10 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase foreach (['getfoobar', 'getFoobar', 'getFooBar'] as $name) { $twig = $this->getEnvironment(true, [], self::$templates, [], [], ['FooObject' => $name]); FooObject::reset(); - $this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic8')->render(self::$params), 'Sandbox allow methods in a case-insensitive way'); + $this->assertEquals('foobarfoobar', $twig->load('1_basic8')->render(self::$params), 'Sandbox allow methods in a case-insensitive way'); $this->assertEquals(2, FooObject::$called['getFooBar'], 'Sandbox only calls method once'); - $this->assertEquals('foobarfoobar', $twig->loadTemplate('1_basic9')->render(self::$params), 'Sandbox allow methods via shortcut names (ie. without get/set)'); + $this->assertEquals('foobarfoobar', $twig->load('1_basic9')->render(self::$params), 'Sandbox allow methods via shortcut names (ie. without get/set)'); } } @@ -236,7 +236,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase ]; $twig = $this->getEnvironment(false, [], self::$templates); - $this->assertEquals('fooFOOfoo', $twig->loadTemplate('2_basic')->render(self::$params), 'Sandbox does nothing if disabled globally and sandboxed not used for the include'); + $this->assertEquals('fooFOOfoo', $twig->load('2_basic')->render(self::$params), 'Sandbox does nothing if disabled globally and sandboxed not used for the include'); self::$templates = [ '3_basic' => '{{ obj.foo }}{% sandbox %}{% include "3_included" %}{% endsandbox %}{{ obj.foo }}', @@ -245,7 +245,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase $twig = $this->getEnvironment(true, [], self::$templates); try { - $twig->loadTemplate('3_basic')->render(self::$params); + $twig->load('3_basic')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed'); } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); @@ -264,7 +264,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase EOF ], ['macro', 'import'], ['escape']); - $this->assertEquals('
username
', $twig->loadTemplate('index')->render([])); + $this->assertEquals('username
', $twig->load('index')->render([])); } public function testSandboxDisabledAfterIncludeFunctionError() @@ -273,7 +273,7 @@ EOF $e = null; try { - $twig->loadTemplate('1_include')->render(self::$params); + $twig->load('1_include')->render(self::$params); } catch (\Throwable $e) { } catch (\Exception $e) { } diff --git a/test/Twig/Tests/Fixtures/functions/block_with_template.test b/test/Twig/Tests/Fixtures/functions/block_with_template.test index 3d403d5b7..37cb7a481 100644 --- a/test/Twig/Tests/Fixtures/functions/block_with_template.test +++ b/test/Twig/Tests/Fixtures/functions/block_with_template.test @@ -12,7 +12,7 @@ --DATA-- return [ 'included_loaded' => $twig->load('included.twig'), - 'included_loaded_internal' => $twig->loadTemplate('included.twig'), + 'included_loaded_internal' => $twig->load('included.twig'), ] --EXPECT-- FOO diff --git a/test/Twig/Tests/Fixtures/functions/include/template_instance.test b/test/Twig/Tests/Fixtures/functions/include/template_instance.test index 8ba956b89..4c8b45083 100644 --- a/test/Twig/Tests/Fixtures/functions/include/template_instance.test +++ b/test/Twig/Tests/Fixtures/functions/include/template_instance.test @@ -5,6 +5,6 @@ --TEMPLATE(foo.twig)-- BAR --DATA-- -return ['foo' => $twig->loadTemplate('foo.twig')] +return ['foo' => $twig->load('foo.twig')] --EXPECT-- BAR FOO diff --git a/test/Twig/Tests/Fixtures/tags/include/template_instance.test b/test/Twig/Tests/Fixtures/tags/include/template_instance.test index 4b2285e50..4fb862a17 100644 --- a/test/Twig/Tests/Fixtures/tags/include/template_instance.test +++ b/test/Twig/Tests/Fixtures/tags/include/template_instance.test @@ -1,10 +1,10 @@ --TEST-- -"include" tag accepts Twig_Template instance +"include" tag accepts \Twig\TemplateWrapper instance --TEMPLATE-- {% include foo %} FOO --TEMPLATE(foo.twig)-- BAR --DATA-- -return ['foo' => $twig->loadTemplate('foo.twig')] +return ['foo' => $twig->load('foo.twig')] --EXPECT-- BAR FOO diff --git a/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test b/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test index 9d62cdba7..a5a223886 100644 --- a/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test +++ b/test/Twig/Tests/Fixtures/tags/inheritance/template_instance.test @@ -9,6 +9,6 @@ --TEMPLATE(foo.twig)-- {% block content %}BAR{% endblock %} --DATA-- -return ['foo' => $twig->loadTemplate('foo.twig')] +return ['foo' => $twig->load('foo.twig')] --EXPECT-- BARFOO diff --git a/test/Twig/Tests/Fixtures/tests/defined_for_blocks_with_template.test b/test/Twig/Tests/Fixtures/tests/defined_for_blocks_with_template.test index f713cd236..68540de7a 100644 --- a/test/Twig/Tests/Fixtures/tests/defined_for_blocks_with_template.test +++ b/test/Twig/Tests/Fixtures/tests/defined_for_blocks_with_template.test @@ -9,7 +9,7 @@ --DATA-- return [ 'included_loaded' => $twig->load('included.twig'), - 'included_loaded_internal' => $twig->loadTemplate('included.twig'), + 'included_loaded_internal' => $twig->load('included.twig'), ] --EXPECT-- ok diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php index f03fead99..86e58e6da 100644 --- a/test/Twig/Tests/Loader/FilesystemTest.php +++ b/test/Twig/Tests/Loader/FilesystemTest.php @@ -182,10 +182,10 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase $twig = new Environment($loader); - $template = $twig->loadTemplate('blocks.html.twig'); + $template = $twig->load('blocks.html.twig'); $this->assertSame('block from theme 1', $template->renderBlock('b1', [])); - $template = $twig->loadTemplate('blocks.html.twig'); + $template = $twig->load('blocks.html.twig'); $this->assertSame('block from theme 2', $template->renderBlock('b2', [])); } @@ -211,7 +211,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase $twig = new Environment($loader); - $template = $twig->loadTemplate($templateName); + $template = $twig->load($templateName); $this->assertSame('VALID Child', $template->renderBlock('body', [])); } diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 3d3ffb4b4..1b42b93e1 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -39,7 +39,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase { $templates = ['index' => $template]; $env = new Environment(new ArrayLoader($templates), ['strict_variables' => true]); - $template = $env->loadTemplate('index'); + $template = $env->load('index'); $context = [ 'string' => 'foo', diff --git a/test/Twig/Tests/TemplateWrapperTest.php b/test/Twig/Tests/TemplateWrapperTest.php index 0522895ce..96ca9b01c 100644 --- a/test/Twig/Tests/TemplateWrapperTest.php +++ b/test/Twig/Tests/TemplateWrapperTest.php @@ -25,17 +25,17 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase 'extended' => '{% block extended %}{% endblock %}', ])); - $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = $twig->load('index'); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertFalse($wrapper->hasBlock('bar')); $this->assertEquals(['foo'], $wrapper->getBlockNames()); - $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index_with_use')); + $wrapper = $twig->load('index_with_use'); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('imported')); $this->assertEquals(['imported', 'foo'], $wrapper->getBlockNames()); - $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index_with_extends')); + $wrapper = $twig->load('index_with_extends'); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('extended')); $this->assertEquals(['foo', 'extended'], $wrapper->getBlockNames()); @@ -48,7 +48,7 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase ])); $twig->addGlobal('bar', 'BAR'); - $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = $twig->load('index'); $this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', ['foo' => 'FOO'])); } @@ -59,7 +59,7 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase ])); $twig->addGlobal('bar', 'BAR'); - $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = $twig->load('index'); ob_start(); $wrapper->displayBlock('foo', ['foo' => 'FOO']);