Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 4.0.0 (2026-XX-XX)

* Add an optional `string $template = ''` argument to `IncludeNode::addGetTemplate()`; subclasses overriding this method must declare a compatible parameter
* Remove the obsolete `Twig\Test\NodeTestCase::getTests()` method; override `provideTests()` instead
* Add native return types to the protected extension points in `Twig\Test\IntegrationTestCase` and `Twig\Test\NodeTestCase` and require overriding methods to declare compatible return types
* Remove `TemplateVariable` and `AssignTemplateVariable`; use `MacroVariable` and `AssignMacroVariable` instead
* Add the `isAlwaysAllowedInSandbox()` method to `Twig\TwigCallableInterface` and `Twig\TokenParser\TokenParserInterface`
* Always allow printing a `Markup` object in a sandbox, whatever the security policy is
Expand Down
8 changes: 4 additions & 4 deletions doc/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1042,15 +1042,15 @@ The ``IntegrationTest.php`` file should look like this::

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
protected function getExtensions(): array
{
return [
new CustomTwigExtension1(),
new CustomTwigExtension2(),
];
}

public function getFixturesDir()
protected static function getFixturesDirectory(): string
{
return __DIR__.'/Fixtures/';
}
Expand All @@ -1066,5 +1066,5 @@ Testing the node visitors can be complex, so extend your test cases from
``\Twig\Test\NodeTestCase``. Examples can be found in the Twig repository
`tests/Twig/Node`_ directory.

.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/3.x/tests/Fixtures
.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/3.x/tests/Node
.. _`tests/Twig/Fixtures`: https://github.com/twigphp/Twig/tree/4.x/tests/Fixtures
.. _`tests/Twig/Node`: https://github.com/twigphp/Twig/tree/4.x/tests/Node
4 changes: 2 additions & 2 deletions extra/cache-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
return [
new CacheExtension(),
];
}

protected function getRuntimeLoaders()
protected function getRuntimeLoaders(): array
{
return [
new class implements RuntimeLoaderInterface {
Expand Down
2 changes: 1 addition & 1 deletion extra/cssinliner-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
return [
new CssInlinerExtension(),
Expand Down
2 changes: 1 addition & 1 deletion extra/html-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
return [
new HtmlExtension(),
Expand Down
2 changes: 1 addition & 1 deletion extra/inky-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
return [
new InkyExtension(),
Expand Down
2 changes: 1 addition & 1 deletion extra/intl-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
return [
new IntlExtension(),
Expand Down
2 changes: 1 addition & 1 deletion extra/markdown-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
return [
new MarkdownExtension(),
Expand Down
2 changes: 1 addition & 1 deletion extra/string-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
return [
new StringExtension(),
Expand Down
18 changes: 8 additions & 10 deletions src/Test/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Twig\Test;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Constraint\Exception;
use PHPUnit\Framework\TestCase;
Expand All @@ -38,39 +39,39 @@ abstract protected static function getFixturesDirectory(): string;
/**
* @return RuntimeLoaderInterface[]
*/
protected function getRuntimeLoaders()
protected function getRuntimeLoaders(): array
{
return [];
}

/**
* @return ExtensionInterface[]
*/
protected function getExtensions()
protected function getExtensions(): array
{
return [];
}

/**
* @return TwigFilter[]
*/
protected function getTwigFilters()
protected function getTwigFilters(): array
{
return [];
}

/**
* @return TwigFunction[]
*/
protected function getTwigFunctions()
protected function getTwigFunctions(): array
{
return [];
}

/**
* @return TwigTest[]
*/
protected function getTwigTests()
protected function getTwigTests(): array
{
return [];
}
Expand Down Expand Up @@ -113,10 +114,7 @@ public function testIntegration($file, $message, $condition, $templates, $except
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation);
}

/**
* @group legacy
*/
#[DataProvider('getLegacyTests'), IgnoreDeprecations]
#[DataProvider('getLegacyTests'), Group('legacy'), IgnoreDeprecations]
public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = ''): void
{
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation);
Expand Down Expand Up @@ -331,7 +329,7 @@ protected function doIntegrationTest($file, $message, $condition, $templateSourc
/**
* @return array<string, string>
*/
protected static function parseTemplates($test)
protected static function parseTemplates($test): array
{
$templates = [];
preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, \PREG_SET_ORDER);
Expand Down
13 changes: 1 addition & 12 deletions src/Test/NodeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ abstract class NodeTestCase extends TestCase
{
private Environment $currentEnv;

/**
* @return iterable<array{0: Node, 1: string, 2?: Environment|null, 3?: bool}>
*/
public function getTests()
{
return [];
}

/**
* @return iterable<array{0: Node, 1: string, 2?: Environment|null, 3?: bool}>
*/
Expand All @@ -53,10 +45,7 @@ public function assertNodeCompilation($source, Node $node, ?Environment $environ
}
}

/**
* @return Compiler
*/
protected function getCompiler(?Environment $environment = null)
protected function getCompiler(?Environment $environment = null): Compiler
{
return new Compiler($environment ?? $this->getEnvironment());
}
Expand Down
3 changes: 0 additions & 3 deletions tests/ExpressionParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ public function testSequenceDestructuringUsesAssignmentTargets(): void
$this->assertSame('third', $pairs[2]['value']->getAttribute('name'));
}

/**
* @dataProvider getEmptyDestructuringTests
*/
#[DataProvider('getEmptyDestructuringTests')]
public function testEmptyDestructuringThrows(string $template): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function html()

class IntegrationTest extends IntegrationTestCase
{
public function getExtensions()
public function getExtensions(): array
{
$policy = new SecurityPolicy([], [], [], [], ['dump']);

Expand Down
3 changes: 0 additions & 3 deletions tests/Node/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public static function provideTests(): iterable
return $tests;
}

/**
* @dataProvider getIsBlankData
*/
#[DataProvider('getIsBlankData')]
public function testIsBlank($blank): void
{
Expand Down
9 changes: 0 additions & 9 deletions tests/NodeVisitor/CorrectnessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@

class CorrectnessTest extends TestCase
{
/**
* @dataProvider getFilterBodyNodesData
*/
#[DataProvider('getFilterBodyNodesData')]
public function testFilterBodyNodes($input, $expected): void
{
Expand All @@ -56,9 +53,6 @@ public static function getFilterBodyNodesData()
];
}

/**
* @dataProvider getFilterBodyNodesDataThrowsException
*/
#[DataProvider('getFilterBodyNodesDataThrowsException')]
public function testFilterBodyNodesThrowsException($input): void
{
Expand All @@ -76,9 +70,6 @@ public static function getFilterBodyNodesDataThrowsException()
];
}

/**
* @dataProvider getFilterBodyNodesWithBOMData
*/
#[DataProvider('getFilterBodyNodesWithBOMData')]
public function testFilterBodyNodesWithBOM($emptyText): void
{
Expand Down
3 changes: 0 additions & 3 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ public function testGetVarName(): void
$this->addToAssertionCount(1);
}

/**
* @dataProvider provideMacroTargetExpressions
*/
#[DataProvider('provideMacroTargetExpressions')]
public function testMacroTargetsOnlyCompileAsMacroReferences(string $expression): void
{
Expand Down
21 changes: 0 additions & 21 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ public function testArrayWithStringableKeyIsConsistentAcrossStrictModes(bool $st
$this->assertSame('value', $twig->render('index', ['array' => ['string' => 'value'], 'object' => $key]));
}

/**
* @dataProvider getStringableKeyArrayAccessContainers
*/
#[DataProvider('getStringableKeyArrayAccessContainers')]
public function testStringableKeyIsCoercedForInternalArrayAccess(bool $strict, bool $sandboxed, \ArrayAccess $data): void
{
Expand Down Expand Up @@ -269,9 +266,6 @@ public static function getStringableKeyArrayAccessContainers(): iterable
}
}

/**
* @dataProvider getStrictVariablesModes
*/
#[DataProvider('getStrictVariablesModes')]
public function testArrayAccessWithObjectKeyKeepsTheObjectKey(bool $strict): void
{
Expand All @@ -288,9 +282,6 @@ public function testArrayAccessWithObjectKeyKeepsTheObjectKey(bool $strict): voi
$this->assertSame(0, $key->toStringCalls);
}

/**
* @dataProvider getStrictVariablesModes
*/
#[DataProvider('getStrictVariablesModes')]
public function testArrayAccessLookupDoesNotRepeatOffsetChecks(bool $strict): void
{
Expand Down Expand Up @@ -319,9 +310,6 @@ public function testArrayAccessDefinedTestDoesNotReadTheOffset(): void
$this->assertSame([], $data->offsetGetCalls);
}

/**
* @dataProvider getStrictVariablesModes
*/
#[DataProvider('getStrictVariablesModes')]
public function testRejectedStringableArrayAccessKeyRethrowsOriginalTypeError(bool $strict): void
{
Expand All @@ -344,9 +332,6 @@ public function testRejectedStringableArrayAccessKeyRethrowsOriginalTypeError(bo
$this->assertSame(0, $key->toStringCalls);
}

/**
* @dataProvider getStrictVariablesModes
*/
#[DataProvider('getStrictVariablesModes')]
public function testSandboxDoesNotAuthorizeStringPropertyForArrayAccessObjectKey(bool $strict): void
{
Expand All @@ -368,9 +353,6 @@ public function testSandboxDoesNotAuthorizeStringPropertyForArrayAccessObjectKey
}
}

/**
* @dataProvider getStrictVariablesModes
*/
#[DataProvider('getStrictVariablesModes')]
public function testArrayWithStringableKeyIsCheckedBySandbox(bool $strict): void
{
Expand All @@ -395,9 +377,6 @@ public function testArrayWithStringableKeyIsCheckedBySandbox(bool $strict): void
$this->assertSame(1, $key->toStringCalls);
}

/**
* @dataProvider getStrictVariablesModes
*/
#[DataProvider('getStrictVariablesModes')]
public function testInternalArrayAccessWithStringableKeyIsCheckedBySandbox(bool $strict): void
{
Expand Down
27 changes: 27 additions & 0 deletions tests/Test/IntegrationTestCaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* 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.
*/

namespace Twig\Tests\Test;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Twig\Test\IntegrationTestCase;

final class IntegrationTestCaseTest extends TestCase
{
public function testLegacyIntegrationTestsAreInLegacyGroup(): void
{
$attributes = (new \ReflectionMethod(IntegrationTestCase::class, 'testLegacyIntegration'))->getAttributes(Group::class);

$this->assertCount(1, $attributes);
$this->assertSame('legacy', $attributes[0]->newInstance()->name());
}
}
Loading