Replace template loader mocks by ArrayLoader

This commit is contained in:
Fabien Potencier
2024-07-23 23:20:37 +02:00
parent 5036ab2a4a
commit e4e95f5b86
19 changed files with 101 additions and 103 deletions
+17 -17
View File
@@ -14,7 +14,7 @@ namespace Twig\Tests;
use PHPUnit\Framework\TestCase;
use Twig\Environment;
use Twig\Error\SyntaxError;
use Twig\Loader\LoaderInterface;
use Twig\Loader\ArrayLoader;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\Binary\ConcatBinary;
use Twig\Node\Expression\ConstantExpression;
@@ -31,7 +31,7 @@ class ExpressionParserTest extends TestCase
{
$this->expectException(SyntaxError::class);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source($template, 'index')));
}
@@ -59,7 +59,7 @@ class ExpressionParserTest extends TestCase
*/
public function testSequenceExpression($template, $expected)
{
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$stream = $env->tokenize($source = new Source($template, ''));
$parser = new Parser($env);
$expected->setSourceContext($source);
@@ -74,7 +74,7 @@ class ExpressionParserTest extends TestCase
{
$this->expectException(SyntaxError::class);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source($template, 'index')));
}
@@ -200,7 +200,7 @@ class ExpressionParserTest extends TestCase
{
$this->expectException(SyntaxError::class);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$stream = $env->tokenize(new Source('{{ "a" "b" }}', 'index'));
$parser = new Parser($env);
@@ -212,7 +212,7 @@ class ExpressionParserTest extends TestCase
*/
public function testStringExpression($template, $expected)
{
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
$stream = $env->tokenize($source = new Source($template, ''));
$parser = new Parser($env);
$expected->setSourceContext($source);
@@ -268,7 +268,7 @@ class ExpressionParserTest extends TestCase
{
$this->expectException(SyntaxError::class);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{{ foo.bar(name="Foo") }}', 'index')));
@@ -278,7 +278,7 @@ class ExpressionParserTest extends TestCase
{
$this->expectException(SyntaxError::class);
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')));
@@ -289,7 +289,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{% macro foo("a") %}{% endmacro %}', 'index')));
@@ -303,7 +303,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('A default value for an argument must be a constant (a boolean, a string, a number, a sequence, or a mapping) in "index" at line 1');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source($template, 'index')));
@@ -322,7 +322,7 @@ class ExpressionParserTest extends TestCase
*/
public function testMacroDefinitionSupportsConstantDefaultValues($template)
{
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source($template, 'index')));
@@ -350,7 +350,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{{ cycl() }}', 'index')));
@@ -361,7 +361,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unknown "foobar" function in "index" at line 1.');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{{ foobar() }}', 'index')));
@@ -372,7 +372,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{{ 1|lowe }}', 'index')));
@@ -383,7 +383,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unknown "foobar" filter in "index" at line 1.');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{{ 1|foobar }}', 'index')));
@@ -394,7 +394,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unknown "nul" test. Did you mean "null" in "index" at line 1');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$stream = $env->tokenize(new Source('{{ 1 is nul }}', 'index'));
$parser->parse($stream);
@@ -405,7 +405,7 @@ class ExpressionParserTest extends TestCase
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unknown "foobar" test in "index" at line 1.');
$env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]);
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$parser = new Parser($env);
$parser->parse($env->tokenize(new Source('{{ 1 is foobar }}', 'index')));