From 8a4b77920a8ef2c73078df72752e0ff12c0f9b4e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 3 Jun 2026 18:26:39 +0200 Subject: [PATCH] Add PHPUnit attributes alongside annotations to silence doc-comment metadata deprecations on PHPUnit 11 --- tests/Cache/ChainTest.php | 2 ++ tests/Cache/FilesystemTest.php | 2 ++ tests/Cache/ReadOnlyFilesystemTest.php | 2 ++ tests/CustomExtensionTest.php | 3 ++ tests/DeprecatedCallableInfoTest.php | 2 ++ tests/EnvironmentTest.php | 4 +-- tests/ErrorTest.php | 3 ++ tests/ExpressionParserTest.php | 14 ++++++++ tests/Extension/AttributeExtensionTest.php | 4 +++ tests/Extension/CoreTest.php | 12 +++++++ tests/Extension/EscaperTest.php | 6 ++++ tests/Extension/LegacyDebugFunctionsTest.php | 2 ++ .../LegacyStringLoaderFunctionsTest.php | 2 ++ tests/Extension/SandboxStateChangeTest.php | 3 ++ tests/Extension/SandboxTest.php | 34 +++++++++++++++++++ tests/FileExtensionEscapingStrategyTest.php | 2 ++ tests/LexerTest.php | 11 ++++++ tests/Loader/FilesystemTest.php | 4 +++ tests/Node/Expression/CallTest.php | 2 ++ tests/Node/Expression/ConditionalTest.php | 2 ++ tests/Node/Expression/MacroReferenceTest.php | 2 ++ tests/Node/Expression/NullCoalesceTest.php | 2 ++ tests/Node/NodeTest.php | 5 +++ tests/NodeVisitor/OptimizerTest.php | 2 ++ tests/ParserTest.php | 4 +++ tests/Resources/LegacyCoreTest.php | 2 ++ tests/Runtime/EscaperRuntimeTest.php | 3 ++ tests/TemplateTest.php | 10 ++++++ tests/TokenParser/TypesTokenParserTest.php | 2 ++ tests/Util/CallableArgumentsExtractorTest.php | 4 +++ tests/Util/CallableParametersTest.php | 2 ++ tests/Util/DeprecationCollectorTest.php | 3 -- 32 files changed, 152 insertions(+), 5 deletions(-) diff --git a/tests/Cache/ChainTest.php b/tests/Cache/ChainTest.php index 4383e6034..a14aa4c85 100644 --- a/tests/Cache/ChainTest.php +++ b/tests/Cache/ChainTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Cache; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Cache\ChainCache; use Twig\Cache\FilesystemCache; @@ -215,6 +216,7 @@ class ChainTest extends TestCase /** * @dataProvider provideInput */ + #[DataProvider('provideInput')] public function testGenerateKey($expected, $input) { $cache = new ChainCache([]); diff --git a/tests/Cache/FilesystemTest.php b/tests/Cache/FilesystemTest.php index 85b1e976c..486868d2d 100644 --- a/tests/Cache/FilesystemTest.php +++ b/tests/Cache/FilesystemTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Cache; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Cache\FilesystemCache; use Twig\Tests\FilesystemHelper; @@ -174,6 +175,7 @@ class FilesystemTest extends TestCase * * @dataProvider provideDirectories */ + #[DataProvider('provideDirectories')] public function testGenerateKey($expected, $input) { $cache = new FilesystemCache($input); diff --git a/tests/Cache/ReadOnlyFilesystemTest.php b/tests/Cache/ReadOnlyFilesystemTest.php index d67276b84..78145c95d 100644 --- a/tests/Cache/ReadOnlyFilesystemTest.php +++ b/tests/Cache/ReadOnlyFilesystemTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Cache; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Cache\ReadOnlyFilesystemCache; use Twig\Tests\FilesystemHelper; @@ -112,6 +113,7 @@ class ReadOnlyFilesystemTest extends TestCase * * @dataProvider provideDirectories */ + #[DataProvider('provideDirectories')] public function testGenerateKey($expected, $input) { $cache = new ReadOnlyFilesystemCache($input); diff --git a/tests/CustomExtensionTest.php b/tests/CustomExtensionTest.php index 9f1fbd325..3d3712c71 100644 --- a/tests/CustomExtensionTest.php +++ b/tests/CustomExtensionTest.php @@ -20,6 +20,8 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Extension\ExtensionInterface; @@ -32,6 +34,7 @@ class CustomExtensionTest extends TestCase * * @dataProvider provideInvalidExtensions */ + #[DataProvider('provideInvalidExtensions'), Group('legacy')] public function testGetInvalidOperators(ExtensionInterface $extension, $expectedExceptionMessage) { $env = new Environment(new ArrayLoader()); diff --git a/tests/DeprecatedCallableInfoTest.php b/tests/DeprecatedCallableInfoTest.php index 166eb9bc4..148717c13 100644 --- a/tests/DeprecatedCallableInfoTest.php +++ b/tests/DeprecatedCallableInfoTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\DeprecatedCallableInfo; @@ -28,6 +29,7 @@ class DeprecatedCallableInfoTest extends TestCase /** * @dataProvider provideTestsForTriggerDeprecation */ + #[DataProvider('provideTestsForTriggerDeprecation')] public function testTriggerDeprecation($expected, DeprecatedCallableInfo $info) { $info->setType('function'); diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index 3c8243d54..639147dfa 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Cache\CacheInterface; @@ -462,9 +463,8 @@ class EnvironmentTest extends TestCase /** * @group legacy - * - * @requires PHP 8 */ + #[Group('legacy')] public function testLegacyEchoingNode() { $loader = new ArrayLoader(['echo_bar' => 'A{% set v %}B{% test %}C{% endset %}D{% test %}E{{ v }}F{% set w %}{% test %}{% endset %}G{{ w }}H']); diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index 1dc145f5e..c9adeaea0 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Attribute\YieldReady; use Twig\Compiler; @@ -144,6 +145,7 @@ EOHTML, /** * @dataProvider getErroredTemplates */ + #[DataProvider('getErroredTemplates')] public function testTwigExceptionAddsFileAndLine($templates, $name, $line) { $loader = new ArrayLoader($templates); @@ -272,6 +274,7 @@ EOHTML, /** * @dataProvider getErrorWithoutLineAndContextData */ + #[DataProvider('getErrorWithoutLineAndContextData')] public function testErrorWithoutLineAndContext(LoaderInterface $loader, bool $debug, bool $addDebugInfo, bool $exceptionWithLineAndContext, int $errorLine) { $twig = new Environment($loader, ['debug' => $debug, 'cache' => false]); diff --git a/tests/ExpressionParserTest.php b/tests/ExpressionParserTest.php index 1bd32ac92..7bf164d34 100644 --- a/tests/ExpressionParserTest.php +++ b/tests/ExpressionParserTest.php @@ -20,6 +20,8 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Attribute\FirstClassTwigCallableReady; @@ -56,6 +58,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getFailingTestsForAssignment */ + #[DataProvider('getFailingTestsForAssignment')] public function testCanOnlyAssignToNames($template) { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); @@ -86,6 +89,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getTestsForSequence */ + #[DataProvider('getTestsForSequence')] public function testSequenceExpression($template, $expected) { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); @@ -99,6 +103,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getFailingTestsForSequence */ + #[DataProvider('getFailingTestsForSequence')] public function testSequenceSyntaxError($template) { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); @@ -247,6 +252,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getTestsForString */ + #[DataProvider('getTestsForString')] public function testStringExpression($template, $expected) { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); @@ -304,6 +310,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getTestsForNullSafeOperator */ + #[DataProvider('getTestsForNullSafeOperator')] public function testNullSafeOperator($template, $data, $expected) { $env = new Environment(new ArrayLoader(['template' => $template]), ['strict_variables' => true]); @@ -376,6 +383,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getTestForInvalidNullSafeOperatorShortCircuiting */ + #[DataProvider('getTestForInvalidNullSafeOperatorShortCircuiting')] public function testInvalidNullSafeOperatorShortCircuiting(string $template, array $data, string $expectedMessage) { $env = new Environment(new ArrayLoader(['template' => $template]), ['strict_variables' => true]); @@ -414,6 +422,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues */ + #[DataProvider('getMacroDefinitionDoesNotSupportNonConstantDefaultValues')] public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template) { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); @@ -436,6 +445,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getMacroDefinitionSupportsConstantDefaultValues */ + #[DataProvider('getMacroDefinitionSupportsConstantDefaultValues')] public function testMacroDefinitionSupportsConstantDefaultValues($template) { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); @@ -606,6 +616,7 @@ class ExpressionParserTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testNotReadyFunction() { $this->expectDeprecation('Since twig/twig 3.12: Twig node "Twig\Tests\NotReadyFunctionExpression" is not marked as ready for passing a "TwigFunction" in the constructor instead of its name; please update your code and then add #[FirstClassTwigCallableReady] attribute to the constructor.'); @@ -621,6 +632,7 @@ class ExpressionParserTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testNotReadyFilter() { $this->expectDeprecation('Since twig/twig 3.12: Twig node "Twig\Tests\NotReadyFilterExpression" is not marked as ready for passing a "TwigFilter" in the constructor instead of its name; please update your code and then add #[FirstClassTwigCallableReady] attribute to the constructor.'); @@ -636,6 +648,7 @@ class ExpressionParserTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testNotReadyTest() { $this->expectDeprecation('Since twig/twig 3.12: Twig node "Twig\Tests\NotReadyTestExpression" is not marked as ready for passing a "TwigTest" in the constructor instead of its name; please update your code and then add #[FirstClassTwigCallableReady] attribute to the constructor.'); @@ -716,6 +729,7 @@ class ExpressionParserTest extends TestCase /** * @dataProvider getBindingPowerTests */ + #[DataProvider('getBindingPowerTests')] public function testBindingPower(string $expression, string $expectedExpression, mixed $expectedResult, array $context = []) { $env = new Environment(new ArrayLoader([ diff --git a/tests/Extension/AttributeExtensionTest.php b/tests/Extension/AttributeExtensionTest.php index 41b215c30..f6b6d9242 100644 --- a/tests/Extension/AttributeExtensionTest.php +++ b/tests/Extension/AttributeExtensionTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\Extension; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\DeprecatedCallableInfo; use Twig\Error\RuntimeError; @@ -28,6 +29,7 @@ class AttributeExtensionTest extends TestCase /** * @dataProvider provideFilters */ + #[DataProvider('provideFilters')] public function testFilter(string $name, string $method, array $options) { $extension = new AttributeExtension(ExtensionWithAttributes::class); @@ -57,6 +59,7 @@ class AttributeExtensionTest extends TestCase /** * @dataProvider provideFunctions */ + #[DataProvider('provideFunctions')] public function testFunction(string $name, string $method, array $options) { $extension = new AttributeExtension(ExtensionWithAttributes::class); @@ -86,6 +89,7 @@ class AttributeExtensionTest extends TestCase /** * @dataProvider provideTests */ + #[DataProvider('provideTests')] public function testTest(string $name, string $method, array $options) { $extension = new AttributeExtension(ExtensionWithAttributes::class); diff --git a/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index 2828d297c..ac8839369 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -20,6 +20,8 @@ namespace Twig\Tests\Extension; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Environment; @@ -37,6 +39,7 @@ class CoreTest extends TestCase /** * @dataProvider provideCycleCases */ + #[DataProvider('provideCycleCases')] public function testCycleFunction($values, $position, $expected) { $this->assertSame($expected, CoreExtension::cycle($values, $position)); @@ -60,6 +63,7 @@ class CoreTest extends TestCase /** * @dataProvider provideCycleInvalidCases */ + #[DataProvider('provideCycleInvalidCases')] public function testCycleFunctionThrowRuntimeError($values, mixed $position = null) { $this->expectException(RuntimeError::class); @@ -78,6 +82,7 @@ class CoreTest extends TestCase /** * @dataProvider getRandomFunctionTestData */ + #[DataProvider('getRandomFunctionTestData')] public function testRandomFunction(array $expectedInArray, $value1, $value2 = null) { for ($i = 0; $i < 100; ++$i) { @@ -178,6 +183,7 @@ class CoreTest extends TestCase /** * @dataProvider provideTwigFirstCases */ + #[DataProvider('provideTwigFirstCases')] public function testTwigFirst($expected, $input) { $this->assertSame($expected, CoreExtension::first('UTF-8', $input)); @@ -199,6 +205,7 @@ class CoreTest extends TestCase /** * @dataProvider provideTwigLastCases */ + #[DataProvider('provideTwigLastCases')] public function testTwigLast($expected, $input) { $this->assertSame($expected, CoreExtension::last('UTF-8', $input)); @@ -220,6 +227,7 @@ class CoreTest extends TestCase /** * @dataProvider provideArrayKeyCases */ + #[DataProvider('provideArrayKeyCases')] public function testArrayKeysFilter(array $expected, $input) { $this->assertSame($expected, CoreExtension::keys($input)); @@ -243,6 +251,7 @@ class CoreTest extends TestCase /** * @dataProvider provideInFilterCases */ + #[DataProvider('provideInFilterCases')] public function testInFilter($expected, $value, $compare) { $this->assertSame($expected, CoreExtension::inFilter($value, $compare)); @@ -271,6 +280,7 @@ class CoreTest extends TestCase /** * @dataProvider provideSliceFilterCases */ + #[DataProvider('provideSliceFilterCases')] public function testSliceFilter($expected, $input, $start, $length = null, $preserveKeys = false) { $this->assertSame($expected, CoreExtension::slice('UTF-8', $input, $start, $length, $preserveKeys)); @@ -300,6 +310,7 @@ class CoreTest extends TestCase /** * @dataProvider provideCompareCases */ + #[DataProvider('provideCompareCases')] public function testCompare($expected, $a, $b) { $this->assertSame($expected, CoreExtension::compare($a, $b)); @@ -414,6 +425,7 @@ class CoreTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testCycleWithArrayAccessAndTraversableButNotCountable() { $this->expectDeprecation('Since twig/twig 3.12: Passing a non-countable sequence of values to "Twig\Extension\CoreExtension::cycle()" is deprecated.'); diff --git a/tests/Extension/EscaperTest.php b/tests/Extension/EscaperTest.php index 09aa4ca79..71d816040 100644 --- a/tests/Extension/EscaperTest.php +++ b/tests/Extension/EscaperTest.php @@ -20,6 +20,8 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Extension\EscaperExtension; @@ -34,6 +36,7 @@ class EscaperTest extends TestCase * * @group legacy */ + #[DataProvider('provideCustomEscaperCases'), Group('legacy')] public function testCustomEscaper($expected, $string, $strategy) { $twig = new Environment(new ArrayLoader()); @@ -56,6 +59,7 @@ class EscaperTest extends TestCase * * @group legacy */ + #[DataProvider('provideCustomEscaperCases'), Group('legacy')] public function testCustomEscaperWithoutCallingSetEscaperRuntime($expected, $string, $strategy) { $twig = new Environment(new ArrayLoader()); @@ -67,6 +71,7 @@ class EscaperTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testCustomEscapersOnMultipleEnvs() { $env1 = new Environment(new ArrayLoader()); @@ -84,6 +89,7 @@ class EscaperTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testSafeClassesUseCustomRuntimeLoader() { $runtime = new EscaperRuntime(); diff --git a/tests/Extension/LegacyDebugFunctionsTest.php b/tests/Extension/LegacyDebugFunctionsTest.php index 4cab76200..73716834a 100644 --- a/tests/Extension/LegacyDebugFunctionsTest.php +++ b/tests/Extension/LegacyDebugFunctionsTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\Extension; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Extension\DebugExtension; @@ -19,6 +20,7 @@ use Twig\Loader\ArrayLoader; /** * @group legacy */ +#[Group('legacy')] class LegacyDebugFunctionsTest extends TestCase { public function testDump() diff --git a/tests/Extension/LegacyStringLoaderFunctionsTest.php b/tests/Extension/LegacyStringLoaderFunctionsTest.php index a6cb31df0..8bebf5609 100644 --- a/tests/Extension/LegacyStringLoaderFunctionsTest.php +++ b/tests/Extension/LegacyStringLoaderFunctionsTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\Extension; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Extension\StringLoaderExtension; @@ -19,6 +20,7 @@ use Twig\Loader\ArrayLoader; /** * @group legacy */ +#[Group('legacy')] class LegacyStringLoaderFunctionsTest extends TestCase { public function testTemplateFromString() diff --git a/tests/Extension/SandboxStateChangeTest.php b/tests/Extension/SandboxStateChangeTest.php index d948ac147..f6981517c 100644 --- a/tests/Extension/SandboxStateChangeTest.php +++ b/tests/Extension/SandboxStateChangeTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\Extension; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Environment; @@ -102,6 +103,7 @@ class SandboxStateChangeTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicyDecisionFlip() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -197,6 +199,7 @@ class SandboxStateChangeTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testSandboxTagAroundIncludeOfPreWarmedTemplate() { $this->expectDeprecation('Since twig/twig 3.15: The "sandbox" tag is deprecated in "wrapper" at line 1.'); diff --git a/tests/Extension/SandboxTest.php b/tests/Extension/SandboxTest.php index 25b71f6ce..0b94fb7aa 100644 --- a/tests/Extension/SandboxTest.php +++ b/tests/Extension/SandboxTest.php @@ -20,6 +20,8 @@ namespace Twig\Tests\Extension; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Environment; @@ -99,6 +101,7 @@ class SandboxTest extends TestCase /** * @dataProvider getSandboxedForCoreTagsTests */ + #[DataProvider('getSandboxedForCoreTagsTests')] public function testSandboxForCoreTags(string $tag, string $template) { $twig = $this->getEnvironment(true, [], self::$templates, []); @@ -137,6 +140,7 @@ class SandboxTest extends TestCase * * @group legacy */ + #[DataProvider('getSandboxedForExtendsAndUseTagsTests'), Group('legacy')] public function testSandboxForExtendsAndUseTags(string $tag, string $template) { $this->expectDeprecation(\sprintf('Since twig/twig 3.12: The "%s" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitly in your sandbox policy if needed (or enable strict mode on the security policy to opt-in to the 4.0 behavior now).', $tag)); @@ -156,6 +160,7 @@ class SandboxTest extends TestCase * * @group legacy */ + #[DataProvider('getSandboxedForParserCallableFunctionsTests'), Group('legacy')] public function testSandboxForParserCallableFunctions(string $function, string $templateName, array $extraTemplates, array $allowedTags, array $allowedMethods, array $allowedProperties, array $context, string $expected) { $this->expectDeprecation(\sprintf('Since twig/twig 3.27: The "%s" function is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitly in your sandbox policy if needed (or enable strict mode on the security policy to opt-in to the 4.0 behavior now).', $function)); @@ -216,6 +221,7 @@ class SandboxTest extends TestCase /** * @dataProvider getAllowedParserCallableFunctionsTests */ + #[DataProvider('getAllowedParserCallableFunctionsTests')] public function testSandboxWithAllowedParserCallableFunctions(string $templateName, array $extraTemplates, array $allowedTags, array $allowedMethods, array $allowedProperties, array $allowedFunctions, array $context, string $expected) { $twig = $this->getEnvironment(true, [], $extraTemplates, $allowedTags, [], $allowedMethods, $allowedProperties, $allowedFunctions); @@ -255,6 +261,7 @@ class SandboxTest extends TestCase /** * @dataProvider getStrictSandboxRejectsGrandfatheredTagsTests */ + #[DataProvider('getStrictSandboxRejectsGrandfatheredTagsTests')] public function testStrictSandboxRejectsGrandfatheredTags(string $tag, string $template) { $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], [], null, true); @@ -274,6 +281,7 @@ class SandboxTest extends TestCase /** * @dataProvider getStrictSandboxRejectsGrandfatheredFunctionsTests */ + #[DataProvider('getStrictSandboxRejectsGrandfatheredFunctionsTests')] public function testStrictSandboxRejectsGrandfatheredFunctions(string $function, string $templateName, array $extraTemplates, array $allowedTags, array $context) { $twig = $this->getEnvironment(true, [], $extraTemplates, $allowedTags, [], [], [], [], null, true); @@ -391,6 +399,7 @@ class SandboxTest extends TestCase /** * @dataProvider provideNonStringArrayAccessKeys */ + #[DataProvider('provideNonStringArrayAccessKeys')] public function testSandboxNonStringKeyAccessDoesNotTriggerImplicitConversionDeprecation(string $template, string $expectedKey) { $loader = new ArrayLoader(['t' => $template]); @@ -449,6 +458,7 @@ class SandboxTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testIfSandBoxIsDisabledAfterSyntaxErrorLegacy() { $twig = $this->getEnvironment(false, [], self::$templates); @@ -553,6 +563,7 @@ class SandboxTest extends TestCase /** * @dataProvider getSandboxUnallowedToStringTests */ + #[DataProvider('getSandboxUnallowedToStringTests')] public function testSandboxUnallowedToString($template) { $twig = $this->getEnvironment(true, [], ['index' => $template], ['if', 'do', 'for', 'set'], ['upper', 'join', 'replace', 'format', 'split'], ['Twig\Tests\Extension\FooObject' => 'getAnotherFooObject'], [], ['random', 'range', 'my_func']); @@ -766,6 +777,7 @@ class SandboxTest extends TestCase /** * @dataProvider getSandboxAllowedToStringTests */ + #[DataProvider('getSandboxAllowedToStringTests')] public function testSandboxAllowedToString($template, $output) { $twig = $this->getEnvironment(true, [], ['index' => $template], ['set', 'do'], [], ['Twig\Tests\Extension\FooObject' => ['foo', 'getAnotherFooObject']]); @@ -1048,6 +1060,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSandboxTagIncludeWithPreloadedTemplate() { $twig = $this->getEnvironment(false, [], [ @@ -1065,6 +1078,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSandboxTagIncludeIgnoreMissingWithPreloadedTemplate() { $twig = $this->getEnvironment(false, [], [ @@ -1193,6 +1207,7 @@ EOF /** * @dataProvider getStringableTraversableBypassTemplates */ + #[DataProvider('getStringableTraversableBypassTemplates')] public function testSandboxBlocksToStringInStringableTraversable(string $template) { $twig = $this->getEnvironment( @@ -1224,6 +1239,7 @@ EOF * * @dataProvider getStringableTraversableBypassTemplates */ + #[DataProvider('getStringableTraversableBypassTemplates'), Group('legacy')] public function testSourcePolicySandboxBlocksToStringInStringableTraversable(string $template) { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1279,6 +1295,7 @@ EOF /** * @dataProvider getCyclicTraversableTemplates */ + #[DataProvider('getCyclicTraversableTemplates')] public function testSandboxHandlesCyclicTraversableWithoutStackOverflow(string $template) { // A self-referencing IteratorAggregate must not cause the sandbox policy @@ -1308,6 +1325,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicySandboxBlocksToStringInTraversableJoin() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1333,6 +1351,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicySandboxBlocksToStringInTraversableReplace() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1412,6 +1431,7 @@ EOF /** * @dataProvider getSafePhpTypesSkipToStringWrap */ + #[DataProvider('getSafePhpTypesSkipToStringWrap')] public function testSafePhpParamTypesSkipToStringWrap(string $template, callable $func, array $params): void { // The sandbox visitor must not wrap arguments whose target PHP @@ -1465,6 +1485,7 @@ EOF /** * @dataProvider getUnsafePhpTypesStillWrap */ + #[DataProvider('getUnsafePhpTypesStillWrap')] public function testUnsafePhpParamTypesStillWrap(string $template, callable $func, array $params): void { // Conversely, an unsafe parameter type (`mixed`, untyped, `string`, @@ -1497,6 +1518,7 @@ EOF /** * @dataProvider getOpenPhpTypesStillWrap */ + #[DataProvider('getOpenPhpTypesStillWrap')] public function testOpenPhpParamTypesStillWrap(callable $func, object $obj, string $class): void { // Interfaces and non-final classes are "open": a Stringable subtype @@ -1642,6 +1664,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicySandboxBlocksColumnFilterOnDisallowedProperty() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1668,6 +1691,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicySandboxBlocksColumnFilterOnDisallowedIndex() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1694,6 +1718,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicySandboxAllowsColumnFilterOnAllowedProperty() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1714,6 +1739,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicySandboxBlocksColumnFilterOnMagicGetter() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1751,6 +1777,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSandboxSourcePolicyEnableReturningFalse() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1767,6 +1794,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSandboxSourcePolicyEnableReturningTrue() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1784,6 +1812,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSandboxSourcePolicyFalseDoesntOverrideOtherEnables() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1803,6 +1832,7 @@ EOF * * @dataProvider provideSourcePolicyArrowBlockedTemplates */ + #[DataProvider('provideSourcePolicyArrowBlockedTemplates'), Group('legacy')] public function testSourcePolicyBlocksNonClosureCallableInArrow(string $template) { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1835,6 +1865,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testSourcePolicyAllowsClosureInArrow() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1853,6 +1884,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testNonSandboxedSourcePolicyAllowsNonClosureCallable() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1892,6 +1924,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testNeedsIsSandboxedFilterFollowsSourcePolicy() { $this->expectDeprecation('Since twig/twig 3.27.0: The "Twig\Sandbox\SourcePolicyInterface" interface is deprecated with no replacement, do not pass an instance to "Twig\Extension\SandboxExtension".'); @@ -1947,6 +1980,7 @@ EOF /** * @group legacy */ + #[Group('legacy')] public function testNeedsIsSandboxedHelperTriggersDeprecationForCustomImplementation() { $callable = new LegacyTwigCallableWithoutNeedsIsSandboxed(); diff --git a/tests/FileExtensionEscapingStrategyTest.php b/tests/FileExtensionEscapingStrategyTest.php index 8b0581081..75eb6c56e 100644 --- a/tests/FileExtensionEscapingStrategyTest.php +++ b/tests/FileExtensionEscapingStrategyTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\FileExtensionEscapingStrategy; @@ -28,6 +29,7 @@ class FileExtensionEscapingStrategyTest extends TestCase /** * @dataProvider getGuessData */ + #[DataProvider('getGuessData')] public function testGuess($strategy, $filename) { $this->assertSame($strategy, FileExtensionEscapingStrategy::guess($filename)); diff --git a/tests/LexerTest.php b/tests/LexerTest.php index 04f0770bd..0b2ae755a 100644 --- a/tests/LexerTest.php +++ b/tests/LexerTest.php @@ -20,6 +20,8 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Environment; @@ -183,6 +185,7 @@ class LexerTest extends TestCase /** * @dataProvider getStringWithEscapedDelimiter */ + #[DataProvider('getStringWithEscapedDelimiter')] public function testStringWithEscapedDelimiter(string $template, string $expected) { $lexer = new Lexer(new Environment(new ArrayLoader())); @@ -259,6 +262,7 @@ class LexerTest extends TestCase * * @dataProvider getStringWithEscapedDelimiterProducingDeprecation */ + #[DataProvider('getStringWithEscapedDelimiterProducingDeprecation'), Group('legacy')] public function testStringWithEscapedDelimiterProducingDeprecation(string $template, string $expected, string $expectedDeprecation) { $this->expectDeprecation($expectedDeprecation); @@ -536,6 +540,7 @@ bar /** * @dataProvider getTemplateForErrorsAtTheEndOfTheStream */ + #[DataProvider('getTemplateForErrorsAtTheEndOfTheStream')] public function testErrorsAtTheEndOfTheStream(string $template) { $lexer = new Lexer(new Environment(new ArrayLoader())); @@ -559,6 +564,7 @@ bar /** * @dataProvider getTemplateForStrings */ + #[DataProvider('getTemplateForStrings')] public function testStrings(string $expected) { $template = '{{ "'.$expected.'" }}'; @@ -597,6 +603,7 @@ bar /** * @dataProvider getTemplateForInlineCommentsForVariable */ + #[DataProvider('getTemplateForInlineCommentsForVariable')] public function testInlineCommentForVariable(string $template) { $lexer = new Lexer(new Environment(new ArrayLoader())); @@ -630,6 +637,7 @@ bar /** * @dataProvider getTemplateForInlineCommentsForBlock */ + #[DataProvider('getTemplateForInlineCommentsForBlock')] public function testInlineCommentForBlock(string $template) { $lexer = new Lexer(new Environment(new ArrayLoader())); @@ -668,6 +676,7 @@ bar /** * @dataProvider getTemplateForInlineCommentsForComment */ + #[DataProvider('getTemplateForInlineCommentsForComment')] public function testInlineCommentForComment(string $template) { $lexer = new Lexer(new Environment(new ArrayLoader())); @@ -685,6 +694,7 @@ bar /** * @dataProvider getTemplateForUnclosedBracketInExpression */ + #[DataProvider('getTemplateForUnclosedBracketInExpression')] public function testUnclosedBracketInExpression(string $template, string $bracket) { $lexer = new Lexer(new Environment(new ArrayLoader())); @@ -706,6 +716,7 @@ bar /** * @dataProvider getTemplateForUnexpectedBracketInExpression */ + #[DataProvider('getTemplateForUnexpectedBracketInExpression')] public function testUnexpectedBracketInExpression(string $template, string $bracket) { $lexer = new Lexer(new Environment(new ArrayLoader())); diff --git a/tests/Loader/FilesystemTest.php b/tests/Loader/FilesystemTest.php index f4c0b972c..f964afbc1 100644 --- a/tests/Loader/FilesystemTest.php +++ b/tests/Loader/FilesystemTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Loader; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Error\LoaderError; @@ -38,6 +39,7 @@ class FilesystemTest extends TestCase /** * @dataProvider getSecurityTests */ + #[DataProvider('getSecurityTests')] public function testSecurity($template) { $loader = new FilesystemLoader([__DIR__.'/../Fixtures']); @@ -83,6 +85,7 @@ class FilesystemTest extends TestCase /** * @dataProvider getBasePaths */ + #[DataProvider('getBasePaths')] public function testPaths($basePath, $cacheKey, $rootPath) { $loader = new FilesystemLoader([$basePath.'/normal', $basePath.'/normal_bis'], $rootPath); @@ -218,6 +221,7 @@ class FilesystemTest extends TestCase /** * @dataProvider getArrayInheritanceTests */ + #[DataProvider('getArrayInheritanceTests')] public function testArrayInheritance(string $templateName) { $loader = new FilesystemLoader([]); diff --git a/tests/Node/Expression/CallTest.php b/tests/Node/Expression/CallTest.php index c6530dab9..80a54ccab 100644 --- a/tests/Node/Expression/CallTest.php +++ b/tests/Node/Expression/CallTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Node\Expression; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Twig\Error\SyntaxError; use Twig\Node\EmptyNode; @@ -29,6 +30,7 @@ use Twig\TwigFunction; /** * @group legacy */ +#[Group('legacy')] class CallTest extends TestCase { public function testGetArguments() diff --git a/tests/Node/Expression/ConditionalTest.php b/tests/Node/Expression/ConditionalTest.php index d5448efb3..b7ba8ff70 100644 --- a/tests/Node/Expression/ConditionalTest.php +++ b/tests/Node/Expression/ConditionalTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Node\Expression; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\Group; use Twig\Node\Expression\ConditionalExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Test\NodeTestCase; @@ -27,6 +28,7 @@ use Twig\Test\NodeTestCase; /** * @group legacy */ +#[Group('legacy')] class ConditionalTest extends NodeTestCase { public function testConstructor() diff --git a/tests/Node/Expression/MacroReferenceTest.php b/tests/Node/Expression/MacroReferenceTest.php index 817542c5b..06b048c65 100644 --- a/tests/Node/Expression/MacroReferenceTest.php +++ b/tests/Node/Expression/MacroReferenceTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\Node\Expression; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\MacroReferenceExpression; @@ -21,6 +22,7 @@ class MacroReferenceTest extends TestCase /** * @dataProvider provideInvalidMacroNames */ + #[DataProvider('provideInvalidMacroNames')] public function testConstructorRejectsNonIdentifierName(string $name) { $this->expectException(\LogicException::class); diff --git a/tests/Node/Expression/NullCoalesceTest.php b/tests/Node/Expression/NullCoalesceTest.php index 41a1ce4da..936ed85fc 100644 --- a/tests/Node/Expression/NullCoalesceTest.php +++ b/tests/Node/Expression/NullCoalesceTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Node\Expression; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\Group; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\NullCoalesceExpression; use Twig\Node\Expression\Variable\ContextVariable; @@ -28,6 +29,7 @@ use Twig\Test\NodeTestCase; /** * @group legacy */ +#[Group('legacy')] class NullCoalesceTest extends NodeTestCase { public static function provideTests(): iterable diff --git a/tests/Node/NodeTest.php b/tests/Node/NodeTest.php index a71d936d6..0dc0df934 100644 --- a/tests/Node/NodeTest.php +++ b/tests/Node/NodeTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Node; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Node\NameDeprecation; @@ -84,6 +85,7 @@ EOF, (string) $node); /** * @group legacy */ + #[Group('legacy')] public function testAttributeDeprecationWithoutAlternative() { $node = new NodeForTest([], ['foo' => false]); @@ -96,6 +98,7 @@ EOF, (string) $node); /** * @group legacy */ + #[Group('legacy')] public function testAttributeDeprecationWithAlternative() { $node = new NodeForTest([], ['foo' => false]); @@ -116,6 +119,7 @@ EOF, (string) $node); /** * @group legacy */ + #[Group('legacy')] public function testNodeDeprecationWithoutAlternative() { $node = new NodeForTest(['foo' => $foo = new NodeForTest()]); @@ -128,6 +132,7 @@ EOF, (string) $node); /** * @group legacy */ + #[Group('legacy')] public function testNodeAttributeDeprecationWithAlternative() { $node = new NodeForTest(['foo' => $foo = new NodeForTest()]); diff --git a/tests/NodeVisitor/OptimizerTest.php b/tests/NodeVisitor/OptimizerTest.php index b333f56cc..0cebea8ef 100644 --- a/tests/NodeVisitor/OptimizerTest.php +++ b/tests/NodeVisitor/OptimizerTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\NodeVisitor; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Loader\ArrayLoader; @@ -90,6 +91,7 @@ class OptimizerTest extends TestCase /** * @dataProvider getTestsForForLoopOptimizer */ + #[DataProvider('getTestsForForLoopOptimizer')] public function testForLoopOptimizer($template, $expected) { $env = new Environment(new ArrayLoader(), ['cache' => false]); diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 37c468e88..868dfa7a9 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Error\SyntaxError; @@ -74,6 +75,7 @@ class ParserTest extends TestCase /** * @dataProvider getFilterBodyNodesData */ + #[DataProvider('getFilterBodyNodesData')] public function testFilterBodyNodes($input, $expected) { $parser = $this->getParser(); @@ -103,6 +105,7 @@ class ParserTest extends TestCase /** * @dataProvider getFilterBodyNodesDataThrowsException */ + #[DataProvider('getFilterBodyNodesDataThrowsException')] public function testFilterBodyNodesThrowsException($input) { $parser = $this->getParser(); @@ -124,6 +127,7 @@ class ParserTest extends TestCase /** * @dataProvider getFilterBodyNodesWithBOMData */ + #[DataProvider('getFilterBodyNodesWithBOMData')] public function testFilterBodyNodesWithBOM($emptyNode) { $parser = $this->getParser(); diff --git a/tests/Resources/LegacyCoreTest.php b/tests/Resources/LegacyCoreTest.php index 8eafca622..d6dedab4e 100644 --- a/tests/Resources/LegacyCoreTest.php +++ b/tests/Resources/LegacyCoreTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\Resources; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Error\RuntimeError; @@ -31,6 +32,7 @@ require_once __DIR__.'/../../src/Resources/core.php'; * * @group legacy */ +#[Group('legacy')] class LegacyCoreTest extends TestCase { public function testTwigSortFilterEnforcesGlobalSandbox() diff --git a/tests/Runtime/EscaperRuntimeTest.php b/tests/Runtime/EscaperRuntimeTest.php index 7d0224939..5c4e3e8b5 100644 --- a/tests/Runtime/EscaperRuntimeTest.php +++ b/tests/Runtime/EscaperRuntimeTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests\Runtime; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Error\RuntimeError; use Twig\Runtime\EscaperRuntime; @@ -386,6 +387,7 @@ class EscaperRuntimeTest extends TestCase /** * @dataProvider provideCustomEscaperCases */ + #[DataProvider('provideCustomEscaperCases')] public function testCustomEscaper($expected, $string, $strategy, $charset) { $escaper = new EscaperRuntime(); @@ -405,6 +407,7 @@ class EscaperRuntimeTest extends TestCase /** * @dataProvider provideObjectsForEscaping */ + #[DataProvider('provideObjectsForEscaping')] public function testObjectEscaping(string $escapedHtml, string $escapedJs, array $safeClasses) { $obj = new Extension_TestClass(); diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index dcd8b4060..d25dce784 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -20,6 +20,7 @@ namespace Twig\Tests; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Error\RuntimeError; @@ -46,6 +47,7 @@ class TemplateTest extends TestCase /** * @dataProvider getAttributeExceptions */ + #[DataProvider('getAttributeExceptions')] public function testGetAttributeExceptions($template, $message) { $templates = ['index' => $template]; @@ -96,6 +98,7 @@ class TemplateTest extends TestCase /** * @dataProvider getGetAttributeWithSandbox */ + #[DataProvider('getGetAttributeWithSandbox')] public function testGetAttributeWithSandbox($object, $item, $allowed) { $twig = new Environment(new ArrayLoader()); @@ -135,6 +138,7 @@ class TemplateTest extends TestCase /** * @dataProvider getRenderTemplateWithoutOutputData */ + #[DataProvider('getRenderTemplateWithoutOutputData')] public function testRenderTemplateWithoutOutput(string $template) { $twig = new Environment(new ArrayLoader(['index' => $template])); @@ -153,6 +157,7 @@ class TemplateTest extends TestCase /** * @dataProvider getNullCoalesceWithImportedMacroData */ + #[DataProvider('getNullCoalesceWithImportedMacroData')] public function testNullCoalesceWithImportedMacro(array $templates, string $expected) { $twig = new Environment(new ArrayLoader($templates)); @@ -255,6 +260,7 @@ class TemplateTest extends TestCase /** * @dataProvider getStrictVariablesModes */ + #[DataProvider('getStrictVariablesModes')] public function testArrayAccessWithStringableKeyIsConsistentAcrossStrictModes(bool $strict) { $twig = new Environment(new ArrayLoader(['index' => '{{ array[object] }}']), [ @@ -307,6 +313,7 @@ class TemplateTest extends TestCase /** * @dataProvider getGetAttributeTests */ + #[DataProvider('getGetAttributeTests')] public function testGetAttribute($defined, $value, $object, $item, $arguments, $type) { $twig = new Environment(new ArrayLoader()); @@ -318,6 +325,7 @@ class TemplateTest extends TestCase /** * @dataProvider getGetAttributeTests */ + #[DataProvider('getGetAttributeTests')] public function testGetAttributeStrict($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null) { $twig = new Environment(new ArrayLoader(), ['strict_variables' => true]); @@ -337,6 +345,7 @@ class TemplateTest extends TestCase /** * @dataProvider getGetAttributeTests */ + #[DataProvider('getGetAttributeTests')] public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type) { $twig = new Environment(new ArrayLoader()); @@ -348,6 +357,7 @@ class TemplateTest extends TestCase /** * @dataProvider getGetAttributeTests */ + #[DataProvider('getGetAttributeTests')] public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type) { $twig = new Environment(new ArrayLoader(), ['strict_variables' => true]); diff --git a/tests/TokenParser/TypesTokenParserTest.php b/tests/TokenParser/TypesTokenParserTest.php index 49e0ac051..9e891b94b 100644 --- a/tests/TokenParser/TypesTokenParserTest.php +++ b/tests/TokenParser/TypesTokenParserTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\TokenParser; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Loader\ArrayLoader; @@ -20,6 +21,7 @@ use Twig\Source; class TypesTokenParserTest extends TestCase { /** @dataProvider getMappingTests */ + #[DataProvider('getMappingTests')] public function testMappingParsing(string $template, array $expected): void { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); diff --git a/tests/Util/CallableArgumentsExtractorTest.php b/tests/Util/CallableArgumentsExtractorTest.php index f97bf57df..aa542c316 100644 --- a/tests/Util/CallableArgumentsExtractorTest.php +++ b/tests/Util/CallableArgumentsExtractorTest.php @@ -20,6 +20,8 @@ namespace Twig\Tests\Util; * file that was distributed with this source code. */ +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Twig\Error\SyntaxError; @@ -98,6 +100,7 @@ class CallableArgumentsExtractorTest extends TestCase /** * @dataProvider getGetArgumentsConversionData */ + #[DataProvider('getGetArgumentsConversionData')] public function testGetArgumentsConversion($arg1, $arg2) { $this->assertEquals([null], $this->getArguments('custom', eval("return fn (\$$arg1) => '';"), [$arg1 => null])); @@ -121,6 +124,7 @@ class CallableArgumentsExtractorTest extends TestCase /** * @group legacy */ + #[Group('legacy')] public function testGetArgumentsConversionForVariadics() { $this->expectDeprecation('Since twig/twig 3.15: Using "snake_case" for variadic arguments is required for a smooth upgrade with Twig 4.0; rename "someNumberVariadic" to "some_number_variadic" in "test.twig" at line 2.'); diff --git a/tests/Util/CallableParametersTest.php b/tests/Util/CallableParametersTest.php index 92e61a578..46b929e92 100644 --- a/tests/Util/CallableParametersTest.php +++ b/tests/Util/CallableParametersTest.php @@ -11,6 +11,7 @@ namespace Twig\Tests\Util; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Twig\Util\CallableParameters; @@ -19,6 +20,7 @@ class CallableParametersTest extends TestCase /** * @dataProvider provideTypes */ + #[DataProvider('provideTypes')] public function testIsStringCoercionSafe(?\ReflectionType $type, bool $expected, ?\ReflectionClass $scope = null): void { $this->assertSame($expected, CallableParameters::isStringCoercionSafe($type, $scope)); diff --git a/tests/Util/DeprecationCollectorTest.php b/tests/Util/DeprecationCollectorTest.php index 9c76a6fcb..5a39e0413 100644 --- a/tests/Util/DeprecationCollectorTest.php +++ b/tests/Util/DeprecationCollectorTest.php @@ -29,9 +29,6 @@ use Twig\Util\DeprecationCollector; class DeprecationCollectorTest extends TestCase { - /** - * @requires PHP 5.3 - */ public function testCollect() { $twig = new Environment(new ArrayLoader());