This commit is contained in:
Fabien Potencier
2026-02-07 09:03:03 +01:00
parent eb516c9740
commit 861215c507
37 changed files with 84 additions and 111 deletions
+8 -12
View File
@@ -1,6 +1,10 @@
<?php
return (new PhpCsFixer\Config())
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
return (new Config())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
@@ -11,19 +15,11 @@ return (new PhpCsFixer\Config())
'no_unreachable_default_argument_value' => false,
'braces' => ['allow_single_line_closure' => true],
'heredoc_to_nowdoc' => false,
'single_line_throw' => false,
'ordered_imports' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'header_comment' => [
'header' => <<<EOF
This file is part of Twig.
(c) Fabien Potencier
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF
],
])
->setRiskyAllowed(true)
->setFinder((new PhpCsFixer\Finder())->in(__DIR__))
->setParallelConfig(ParallelConfigFactory::detect())
->setFinder((new Finder())->in(__DIR__))
;
+2 -2
View File
@@ -36,7 +36,7 @@ fwrite($output, "\n+------------+------------------+---------+---------------+".
fwrite($output, '| Precedence | Operator | Type | Associativity | Description'.str_repeat(' ', $descriptionLength - 11)." |\n");
fwrite($output, '+============+==================+=========+===============+'.str_repeat('=', $descriptionLength + 2).'+');
usort($expressionParsers, fn ($a, $b) => $b->getPrecedence() <=> $a->getPrecedence());
usort($expressionParsers, static fn ($a, $b) => $b->getPrecedence() <=> $a->getPrecedence());
$previous = null;
foreach ($expressionParsers as $expressionParser) {
@@ -72,7 +72,7 @@ fwrite($output, "\n+------------+------------------+---------+---------------+".
fwrite($output, '| Precedence | Operator | Type | Associativity | Description'.str_repeat(' ', $descriptionLength - 11)." |\n");
fwrite($output, '+============+==================+=========+===============+'.str_repeat('=', $descriptionLength + 2).'+');
usort($expressionParsers, function ($a, $b) {
usort($expressionParsers, static function ($a, $b) {
$aPrecedence = $a->getPrecedenceChange() ? $a->getPrecedenceChange()->getNewPrecedence() : $a->getPrecedence();
$bPrecedence = $b->getPrecedenceChange() ? $b->getPrecedenceChange()->getNewPrecedence() : $b->getPrecedence();
+2 -1
View File
@@ -32,7 +32,8 @@
"require-dev": {
"symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0",
"psr/container": "^1.0|^2.0",
"phpstan/phpstan": "^2.0"
"phpstan/phpstan": "^2.0",
"php-cs-fixer/shim": "^3.0"
},
"autoload": {
"files": [
+1 -1
View File
@@ -23,7 +23,7 @@ use SymfonyDocsBuilder\DocBuilder;
(new Application('Twig docs Builder', '1.0'))
->register('build-docs')
->addOption('disable-cache', null, InputOption::VALUE_NONE, 'Use this option to force a full regeneration of all doc contents')
->setCode(function (InputInterface $input, OutputInterface $output) {
->setCode(static function (InputInterface $input, OutputInterface $output) {
$io = new SymfonyStyle($input, $output);
$io->text('Building all Twig docs...');
+1 -1
View File
@@ -29,7 +29,7 @@ class FunctionalTest extends TestCase
$twig = $this->createEnvironment(['index' => '{% cache "city;v1" %}{{- city -}}{% endcache %}'], $cache);
$this->assertSame('Paris', $twig->render('index', ['city' => 'Paris']));
$value = $cache->get('city;v1', function () { throw new \RuntimeException('Key should be in the cache'); });
$value = $cache->get('city;v1', static function () { throw new \RuntimeException('Key should be in the cache'); });
$this->assertSame('Paris', $value);
}
+3 -3
View File
@@ -114,10 +114,10 @@ final class HtmlExtension extends AbstractExtension
}
/**
* @param string|list<string|null> $base
* @param string|list<string|null> $base
* @param array<string, array<string, string|array<string>>> $variants
* @param array<array<string, string|array<string>>> $compoundVariants
* @param array<string, string> $defaultVariant
* @param array<array<string, string|array<string>>> $compoundVariants
* @param array<string, string> $defaultVariant
*
* @internal
*/
@@ -67,8 +67,7 @@ Hello
Great!
{% endapply %}
EOF
, "<h1>Hello</h1>\n+<p>Great!</p>"],
EOF, "<h1>Hello</h1>\n+<p>Great!</p>"],
[<<<EOF
{% apply markdown_to_html %}
Hello
@@ -76,8 +75,7 @@ EOF
Great!
{% endapply %}
EOF
, "<h1>Hello</h1>\n+<p>Great!</p>"],
EOF, "<h1>Hello</h1>\n+<p>Great!</p>"],
["{{ include('html')|markdown_to_html }}", "<h1>Hello</h1>\n+<p>Great!</p>"],
];
}
@@ -37,7 +37,6 @@ if (!method_exists(ContainerBuilder::class, 'getAutoconfiguredAttributes')) {
$this->doLoad($configs, $container);
}
}
}
/**
@@ -51,12 +51,12 @@ class AssignmentExpressionParser extends BinaryOperatorExpressionParser
if ($left instanceof ArrayExpression) {
if ($left->isSequence()) {
return new SequenceDestructuringSetBinary($left, $right, $token->getLine());
} else {
return new ObjectDestructuringSetBinary($left, $right, $token->getLine());
}
} else {
return new SetBinary($left, $right, $token->getLine());
return new ObjectDestructuringSetBinary($left, $right, $token->getLine());
}
return new SetBinary($left, $right, $token->getLine());
}
public function getDescription(): string
+8 -8
View File
@@ -134,7 +134,7 @@ final class CoreExtension extends AbstractExtension
private $dateFormats = ['F j, Y H:i', '%d days'];
private $numberFormat = [0, '.', ','];
private $timezone = null;
private $timezone;
/**
* Sets the default format to be used by the date filter.
@@ -1128,9 +1128,9 @@ final class CoreExtension extends AbstractExtension
}
if ((int) $bTrim == $bTrim) {
return $a <=> (int) $bTrim;
} else {
return (float) $a <=> (float) $bTrim;
}
return (float) $a <=> (float) $bTrim;
}
if (\is_string($a) && \is_int($b)) {
$aTrim = trim($a, " \t\n\r\v\f");
@@ -1139,9 +1139,9 @@ final class CoreExtension extends AbstractExtension
}
if ((int) $aTrim == $aTrim) {
return (int) $aTrim <=> $b;
} else {
return (float) $aTrim <=> (float) $b;
}
return (float) $aTrim <=> (float) $b;
}
// float <=> string
@@ -1179,7 +1179,7 @@ final class CoreExtension extends AbstractExtension
*/
public static function matches(string $regexp, ?string $str): int
{
set_error_handler(function ($t, $m) use ($regexp) {
set_error_handler(static function ($t, $m) use ($regexp) {
throw new RuntimeError(\sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
});
try {
@@ -2148,7 +2148,7 @@ final class CoreExtension extends AbstractExtension
*/
public static function parseBlockFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
{
$fakeFunction = new TwigFunction('block', fn ($name, $template = null) => null);
$fakeFunction = new TwigFunction('block', static fn ($name, $template = null) => null);
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
return new BlockReferenceExpression($args[0], $args[1] ?? null, $line);
@@ -2159,7 +2159,7 @@ final class CoreExtension extends AbstractExtension
*/
public static function parseAttributeFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
{
$fakeFunction = new TwigFunction('attribute', fn ($variable, $attribute, $arguments = null) => null);
$fakeFunction = new TwigFunction('attribute', static fn ($variable, $attribute, $arguments = null) => null);
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
/*
-3
View File
@@ -46,9 +46,6 @@ class Markup implements \Countable, \JsonSerializable, \Stringable
return mb_strlen($this->content, $this->charset);
}
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
+2 -3
View File
@@ -24,7 +24,7 @@ use Twig\Util\ReflectionCallable;
abstract class CallExpression extends AbstractExpression
{
private $reflector = null;
private $reflector;
/**
* @return void
@@ -213,9 +213,8 @@ abstract class CallExpression extends AbstractExpression
} elseif ($callableParameter->isOptional()) {
if (!$parameters) {
break;
} else {
$missingArguments[] = $name;
}
$missingArguments[] = $name;
} else {
throw new SyntaxError(\sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());
}
+3 -3
View File
@@ -447,7 +447,7 @@ class Parser
if (!$function) {
if ($this->shouldIgnoreUnknownTwigCallables()) {
return new TwigFunction($name, fn () => '');
return new TwigFunction($name, static fn () => '');
}
$e = new SyntaxError(\sprintf('Unknown "%s" function.', $name), $line, $this->stream->getSourceContext());
$e->addSuggestions($name, array_keys($this->env->getFunctions()));
@@ -476,7 +476,7 @@ class Parser
}
if (!$filter) {
if ($this->shouldIgnoreUnknownTwigCallables()) {
return new TwigFilter($name, fn () => '');
return new TwigFilter($name, static fn () => '');
}
$e = new SyntaxError(\sprintf('Unknown "%s" filter.', $name), $line, $this->stream->getSourceContext());
$e->addSuggestions($name, array_keys($this->env->getFilters()));
@@ -524,7 +524,7 @@ class Parser
if (!$test) {
if ($this->shouldIgnoreUnknownTwigCallables()) {
return new TwigTest($name, fn () => '');
return new TwigTest($name, static fn () => '');
}
$e = new SyntaxError(\sprintf('Unknown "%s" test.', $name), $line, $this->stream->getSourceContext());
$e->addSuggestions($name, array_keys($this->env->getTests()));
+3 -3
View File
@@ -191,7 +191,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface
throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
}
$string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', function ($matches) {
$string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', static function ($matches) {
$char = $matches[0];
/*
@@ -243,7 +243,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface
throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
}
$string = preg_replace_callback('#[^a-zA-Z0-9]#Su', function ($matches) {
$string = preg_replace_callback('#[^a-zA-Z0-9]#Su', static function ($matches) {
$char = $matches[0];
return \sprintf('\\%X ', 1 === \strlen($char) ? \ord($char) : mb_ord($char, 'UTF-8'));
@@ -264,7 +264,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface
throw new RuntimeError('The string to escape is not a valid UTF-8 string.');
}
$string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', function ($matches) {
$string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', static function ($matches) {
/**
* This function is adapted from code coming from Zend Framework.
*
+3 -3
View File
@@ -158,7 +158,7 @@ abstract class Template
if ($this->env->isDebug()) {
ob_start();
} else {
ob_start(function () { return ''; });
ob_start(static function () { return ''; });
}
$this->displayParentBlock($name, $context, $blocks);
@@ -193,7 +193,7 @@ abstract class Template
if ($this->env->isDebug()) {
ob_start();
} else {
ob_start(function () { return ''; });
ob_start(static function () { return ''; });
}
try {
$this->displayBlock($name, $context, $blocks, $useBlocks);
@@ -367,7 +367,7 @@ abstract class Template
if ($this->env->isDebug()) {
ob_start();
} else {
ob_start(function () { return ''; });
ob_start(static function () { return ''; });
}
try {
$this->display($context);
+1 -1
View File
@@ -273,7 +273,7 @@ abstract class IntegrationTestCase extends TestCase
$deprecations = [];
try {
$prevHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$prevHandler) {
$prevHandler = set_error_handler(static function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$prevHandler) {
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
+1 -1
View File
@@ -54,7 +54,7 @@ final class DeprecationCollector
public function collect(\Traversable $iterator): array
{
$deprecations = [];
set_error_handler(function ($type, $msg) use (&$deprecations) {
set_error_handler(static function ($type, $msg) use (&$deprecations) {
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}
+2 -2
View File
@@ -35,7 +35,7 @@ class DeprecatedCallableInfoTest extends TestCase
$deprecations = [];
try {
set_error_handler(function ($type, $msg) use (&$deprecations) {
set_error_handler(static function ($type, $msg) use (&$deprecations) {
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}
@@ -67,7 +67,7 @@ class DeprecatedCallableInfoTest extends TestCase
$deprecations = [];
try {
set_error_handler(function ($type, $msg) use (&$deprecations) {
set_error_handler(static function ($type, $msg) use (&$deprecations) {
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}
+6 -6
View File
@@ -396,9 +396,9 @@ class EnvironmentTest extends TestCase
public function testUndefinedFunctionCallback()
{
$twig = new Environment(new ArrayLoader());
$twig->registerUndefinedFunctionCallback(function (string $name) {
$twig->registerUndefinedFunctionCallback(static function (string $name) {
if ('dynamic' === $name) {
return new TwigFunction('dynamic', function () { return 'dynamic'; });
return new TwigFunction('dynamic', static function () { return 'dynamic'; });
}
return false;
@@ -412,9 +412,9 @@ class EnvironmentTest extends TestCase
public function testUndefinedFilterCallback()
{
$twig = new Environment(new ArrayLoader());
$twig->registerUndefinedFilterCallback(function (string $name) {
$twig->registerUndefinedFilterCallback(static function (string $name) {
if ('dynamic' === $name) {
return new TwigFilter('dynamic', function () { return 'dynamic'; });
return new TwigFilter('dynamic', static function () { return 'dynamic'; });
}
return false;
@@ -428,9 +428,9 @@ class EnvironmentTest extends TestCase
public function testUndefinedTestCallback()
{
$twig = new Environment(new ArrayLoader());
$twig->registerUndefinedTestCallback(function (string $name) {
$twig->registerUndefinedTestCallback(static function (string $name) {
if ('dynamic' === $name) {
return new TwigTest('dynamic', function () { return 'dynamic'; });
return new TwigTest('dynamic', static function () { return 'dynamic'; });
}
return false;
+3 -3
View File
@@ -488,7 +488,7 @@ class ExpressionParserTest extends TestCase
public function getTests()
{
return [
new TwigTest('*_foo_*_bar', function ($foo, $bar, $a) {}),
new TwigTest('*_foo_*_bar', static function ($foo, $bar, $a) {}),
];
}
});
@@ -503,7 +503,7 @@ class ExpressionParserTest extends TestCase
public function getFunctions()
{
return [
new TwigFunction('*_foo_*_bar', function ($foo, $bar, $a) {}),
new TwigFunction('*_foo_*_bar', static function ($foo, $bar, $a) {}),
];
}
});
@@ -518,7 +518,7 @@ class ExpressionParserTest extends TestCase
public function getFilters()
{
return [
new TwigFilter('*_foo_*_bar', function ($foo, $bar, $a) {}),
new TwigFilter('*_foo_*_bar', static function ($foo, $bar, $a) {}),
];
}
});
+4 -4
View File
@@ -85,7 +85,7 @@ class IntegrationTest extends IntegrationTestCase
// Ensure this does not conflict with `divisible by` and `same as`.
if (\in_array($name, ['divisible', 'same'], true)) {
return new TwigTest($name, fn () => '');
return new TwigTest($name, static fn () => '');
}
return false;
@@ -240,7 +240,7 @@ class TwigTestExtension extends AbstractExtension
new TwigFilter('*_path', [$this, 'dynamic_path']),
new TwigFilter('*_foo_*_bar', [$this, 'dynamic_foo']),
new TwigFilter('not', [$this, 'notFilter']),
new TwigFilter('anon_foo', function ($name) { return '*'.$name.'*'; }),
new TwigFilter('anon_foo', static function ($name) { return '*'.$name.'*'; }),
];
}
@@ -254,8 +254,8 @@ class TwigTestExtension extends AbstractExtension
new TwigFunction('static_call_array', ['Twig\Tests\TwigTestExtension', 'staticCall']),
new TwigFunction('*_path', [$this, 'dynamic_path']),
new TwigFunction('*_foo_*_bar', [$this, 'dynamic_foo']),
new TwigFunction('anon_foo', function ($name) { return '*'.$name.'*'; }),
new TwigFunction('deprecated_function', function () { return 'foo'; }, ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.1', 'not_deprecated_function')]),
new TwigFunction('anon_foo', static function ($name) { return '*'.$name.'*'; }),
new TwigFunction('deprecated_function', static function () { return 'foo'; }, ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.1', 'not_deprecated_function')]),
];
}
+1 -2
View File
@@ -51,8 +51,7 @@ public function block_foo(array \$context, array \$blocks = []): iterable
yield "foo";
yield from [];
}
EOF
, new Environment(new ArrayLoader()),
EOF, new Environment(new ArrayLoader()),
];
return $tests;
+1 -2
View File
@@ -93,8 +93,7 @@ EOF
// line 1
\$$varName = Twig\Tests\Node\\foo();
trigger_deprecation("twig/twig", "1.1", \$$varName." in \"foo.twig\" at line 1.");
EOF
, $environment];
EOF, $environment];
return $tests;
}
+1 -1
View File
@@ -174,7 +174,7 @@ class FilterTest extends NodeTestCase
protected static function createEnvironment(): Environment
{
$env = new Environment(new ArrayLoader());
$env->addFilter(new TwigFilter('anonymous', function () {}));
$env->addFilter(new TwigFilter('anonymous', static function () {}));
$env->addFilter(new TwigFilter('bar', 'Twig\Tests\Node\Expression\twig_tests_filter_dummy', ['needs_environment' => true]));
$env->addFilter(new TwigFilter('bar_closure', \Closure::fromCallable(twig_tests_filter_dummy::class), ['needs_environment' => true]));
$env->addFilter(new TwigFilter('barbar', 'Twig\Tests\Node\Expression\twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true]));
+1 -1
View File
@@ -114,7 +114,7 @@ class FunctionTest extends NodeTestCase
protected static function createEnvironment(): Environment
{
$env = new Environment(new ArrayLoader());
$env->addFunction(new TwigFunction('anonymous', function () {}));
$env->addFunction(new TwigFunction('anonymous', static function () {}));
$env->addFunction(new TwigFunction('foo', 'Twig\Tests\Node\Expression\twig_tests_function_dummy', []));
$env->addFunction(new TwigFunction('foo_closure', \Closure::fromCallable(twig_tests_function_dummy::class), []));
$env->addFunction(new TwigFunction('bar', 'Twig\Tests\Node\Expression\twig_tests_function_dummy', ['needs_environment' => true]));
+1 -1
View File
@@ -88,7 +88,7 @@ class TestTest extends NodeTestCase
protected static function createEnvironment(): Environment
{
$env = new Environment(new ArrayLoader());
$env->addTest(new TwigTest('anonymous', function () {}));
$env->addTest(new TwigTest('anonymous', static function () {}));
$env->addTest(new TwigTest('barbar', 'Twig\Tests\Node\Expression\twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true]));
return $env;
+1 -2
View File
@@ -96,8 +96,7 @@ try {
if (\$_v%s) {
yield from \$_v%s->unwrap()->yield(CoreExtension::toArray(["foo" => true]));
}
EOF
, null, true];
EOF, null, true];
return $tests;
}
+2 -4
View File
@@ -77,8 +77,7 @@ public function macro_foo(\$foo = null, \$bar = "Foo", \$_underscore = null, ...
yield from [];
})(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
}
EOF
, new Environment(new ArrayLoader(), ['use_yield' => true]),
EOF, new Environment(new ArrayLoader(), ['use_yield' => true]),
];
yield 'with use_yield = false' => [$node, <<<EOF
@@ -100,8 +99,7 @@ public function macro_foo(\$foo = null, \$bar = "Foo", \$_underscore = null, ...
yield from [];
})())) ? '' : new Markup(\$tmp, \$this->env->getCharset());
}
EOF
, new Environment(new ArrayLoader(), ['use_yield' => false]),
EOF, new Environment(new ArrayLoader(), ['use_yield' => false]),
];
}
}
+3 -6
View File
@@ -137,8 +137,7 @@ class __TwigTemplate_%x extends Template
return new Source("", "foo.twig", "");
}
}
EOF
, $twig, true];
EOF, $twig, true];
$import = new ImportNode(new ConstantExpression('foo.twig', 1), new AssignTemplateVariable(new TemplateVariable('macro', 2), true), 2);
@@ -227,8 +226,7 @@ class __TwigTemplate_%x extends Template
return new Source("", "foo.twig", "");
}
}
EOF
, $twig, true];
EOF, $twig, true];
$set = new SetNode(false, new Nodes([new AssignContextVariable('foo', 4)]), new Nodes([new ConstantExpression('foo', 4)]), 4);
$body = new BodyNode([$set]);
@@ -321,8 +319,7 @@ class __TwigTemplate_%x extends Template
return new Source("{{ foo }}", "foo.twig", "");
}
}
EOF
, $twig, true];
EOF, $twig, true];
return $tests;
}
+4 -7
View File
@@ -35,14 +35,13 @@ class NodeTest extends TestCase
public function testToString()
{
// callable is not a supported type for a Node attribute, but Drupal uses some apparently
$node = new NodeForTest([], ['value' => function () { return '1'; }], 1);
$node = new NodeForTest([], ['value' => static function () { return '1'; }], 1);
$this->assertEquals(<<<EOF
Twig\Tests\Node\NodeForTest
attributes:
value: \Closure
EOF
, (string) $node
EOF, (string) $node
);
}
@@ -60,8 +59,7 @@ Twig\Tests\Node\NodeForTest
function: Twig\TwigFunction(a_function)
filter: Twig\TwigFilter(a_filter)
test: Twig\TwigTest(a_test)
EOF
, (string) $node);
EOF, (string) $node);
}
public function testToStringWithTag()
@@ -72,8 +70,7 @@ EOF
$this->assertEquals(<<<EOF
Twig\Tests\Node\NodeForTest
tag: tag
EOF
, (string) $node);
EOF, (string) $node);
}
public function testAttributeDeprecationIgnore()
+2 -4
View File
@@ -67,8 +67,7 @@ EOF
yield "foo";
yield from [];
})(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
EOF
, new Environment(new ArrayLoader(), ['use_yield' => true]),
EOF, new Environment(new ArrayLoader(), ['use_yield' => true]),
];
$tests[] = [$node, <<<'EOF'
@@ -77,8 +76,7 @@ $context["foo"] = ('' === $tmp = \Twig\Extension\CoreExtension::captureOutput((f
yield "foo";
yield from [];
})())) ? '' : new Markup($tmp, $this->env->getCharset());
EOF
, new Environment(new ArrayLoader(), ['use_yield' => false]),
EOF, new Environment(new ArrayLoader(), ['use_yield' => false]),
];
$names = new Nodes([new AssignContextVariable('foo', 1)], 1);
+1 -2
View File
@@ -178,8 +178,7 @@ class ParserTest extends TestCase
{% macro foo() %}
{{ foo }}
{% endmacro %}
EOF
, 'index')));
EOF, 'index')));
// The getVarName() must not depend on the template loaders,
// If this test does not throw any exception, that's good.
+1 -2
View File
@@ -39,7 +39,6 @@ index.twig==>embedded.twig::block(body)//1 %d %d 0
index.twig==>embedded.twig//2 %d %d %d
embedded.twig==>included.twig//2 %d %d %d
index.twig==>index.twig::macro(foo)//1 %d %d %d
EOF
, $dumper->dump($this->getProfile()));
EOF, $dumper->dump($this->getProfile()));
}
}
+1 -2
View File
@@ -37,7 +37,6 @@ class HtmlTest extends ProfilerTestCase
<span style="background-color: #ffd">embedded.twig</span>
<span style="background-color: #ffd">included.twig</span>
</pre>
EOF
, $dumper->dump($this->getProfile()));
EOF, $dumper->dump($this->getProfile()));
}
}
+1 -2
View File
@@ -37,7 +37,6 @@ main %d.%dms/%d%
embedded.twig
included.twig
EOF
, $dumper->dump($this->getProfile()));
EOF, $dumper->dump($this->getProfile()));
}
}
+3 -3
View File
@@ -404,8 +404,8 @@ class TemplateTest extends TestCase
]);
// test for Closure::__invoke()
$tests[] = [true, 'closure called', fn (): string => 'closure called', '__invoke', [], $anyType];
$tests[] = [true, 'closure called', fn (): string => 'closure called', '__invoke', [], $methodType];
$tests[] = [true, 'closure called', static fn (): string => 'closure called', '__invoke', [], $anyType];
$tests[] = [true, 'closure called', static fn (): string => 'closure called', '__invoke', [], $methodType];
// tests when input is not an array or object
$tests = array_merge($tests, [
@@ -567,7 +567,7 @@ class TemplatePropertyObject
{
public $defined = 'defined';
public $zero = 0;
public $null = null;
public $null;
public $bar = true;
public $foo = true;
public $baz = 'baz';
+1 -1
View File
@@ -25,7 +25,7 @@ class GuardTokenParserTest extends TestCase
$this->expectNotToPerformAssertions();
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$env->registerUndefinedFunctionCallback(fn ($name) => throw new SyntaxError('boom.'));
$env->registerUndefinedFunctionCallback(static fn ($name) => throw new SyntaxError('boom.'));
(new Parser($env))->parse($env->tokenize(new Source('{% guard function boom %}{% endguard %}', '')));
}
}