From: =?utf-8?q?David_Pr=C3=A9vot?= <taffit@debian.org>
Date: Sat, 15 Feb 2025 15:51:59 +0100
Subject: Compatibility with recent PHPUnit (12)

---
 extra/cssinliner-extra/Tests/LegacyFunctionsTest.php |  2 ++
 extra/html-extra/Tests/LegacyFunctionsTest.php       |  2 ++
 extra/inky-extra/Tests/LegacyFunctionsTest.php       |  2 ++
 extra/markdown-extra/Tests/FunctionalTest.php        |  4 +++-
 extra/markdown-extra/Tests/LegacyFunctionsTest.php   |  2 ++
 tests/EnvironmentTest.php                            |  8 +++-----
 tests/ErrorTest.php                                  |  4 +---
 tests/ExpressionParserTest.php                       | 19 +++++++------------
 tests/Extension/AttributeExtensionTest.php           | 12 +++---------
 tests/Extension/EscaperTest.php                      |  3 +++
 tests/Extension/SandboxTest.php                      | 12 ++++--------
 tests/LexerTest.php                                  |  3 +++
 tests/NodeVisitor/OptimizerTest.php                  |  1 +
 tests/TemplateTest.php                               |  6 +++---
 14 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php b/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php
index d62e267..0b8bd7b 100644
--- a/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php
+++ b/extra/cssinliner-extra/Tests/LegacyFunctionsTest.php
@@ -11,6 +11,7 @@
 
 namespace Twig\Extra\CssInliner\Tests;
 
+use PHPUnit\Framework\Attributes\IgnoreDeprecations;
 use PHPUnit\Framework\TestCase;
 use Twig\Extra\CssInliner\CssInlinerExtension;
 
@@ -21,6 +22,7 @@ use function Twig\Extra\CssInliner\twig_inline_css;
  */
 class LegacyFunctionsTest extends TestCase
 {
+    #[IgnoreDeprecations]
     public function testInlineCss()
     {
         $this->assertSame(CssInlinerExtension::inlineCss('<p>body</p>', 'p { color: red }'), twig_inline_css('<p>body</p>', 'p { color: red }'));
diff --git a/extra/html-extra/Tests/LegacyFunctionsTest.php b/extra/html-extra/Tests/LegacyFunctionsTest.php
index accf8af..757553c 100644
--- a/extra/html-extra/Tests/LegacyFunctionsTest.php
+++ b/extra/html-extra/Tests/LegacyFunctionsTest.php
@@ -11,6 +11,7 @@
 
 namespace Twig\Extra\Html\Tests;
 
+use PHPUnit\Framework\Attributes\IgnoreDeprecations;
 use PHPUnit\Framework\TestCase;
 use Twig\Extra\Html\HtmlExtension;
 
@@ -19,6 +20,7 @@ use Twig\Extra\Html\HtmlExtension;
  */
 class LegacyFunctionsTest extends TestCase
 {
+    #[IgnoreDeprecations]
     public function testHtmlToMarkdown()
     {
         $this->assertSame(HtmlExtension::htmlClasses(['charset' => 'utf-8']), twig_html_classes(['charset' => 'utf-8']));
diff --git a/extra/inky-extra/Tests/LegacyFunctionsTest.php b/extra/inky-extra/Tests/LegacyFunctionsTest.php
index 4810235..e83848c 100644
--- a/extra/inky-extra/Tests/LegacyFunctionsTest.php
+++ b/extra/inky-extra/Tests/LegacyFunctionsTest.php
@@ -11,6 +11,7 @@
 
 namespace Twig\Extra\Inky\Tests;
 
+use PHPUnit\Framework\Attributes\IgnoreDeprecations;
 use PHPUnit\Framework\TestCase;
 use Twig\Extra\Inky\InkyExtension;
 
@@ -21,6 +22,7 @@ use function Twig\Extra\Inky\twig_inky;
  */
 class LegacyFunctionsTest extends TestCase
 {
+    #[IgnoreDeprecations]
     public function testInlineCss()
     {
         $this->assertSame(InkyExtension::inky('<p>Foo</p>'), twig_inky('<p>Foo</p>'));
diff --git a/extra/markdown-extra/Tests/FunctionalTest.php b/extra/markdown-extra/Tests/FunctionalTest.php
index 40449b3..ecfffb2 100644
--- a/extra/markdown-extra/Tests/FunctionalTest.php
+++ b/extra/markdown-extra/Tests/FunctionalTest.php
@@ -12,6 +12,7 @@
 namespace Twig\Extra\Markdown\Tests;
 
 use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\IgnoreDeprecations;
 use PHPUnit\Framework\TestCase;
 use Twig\Environment;
 use Twig\Extra\Markdown\DefaultMarkdown;
@@ -26,7 +27,8 @@ use Twig\RuntimeLoader\RuntimeLoaderInterface;
 class FunctionalTest extends TestCase
 {
     #[DataProvider('getMarkdownTests')]
-    public function testMarkdown(string $template, string $expected)
+    #[IgnoreDeprecations]
+    public function testMarkdown(string $template, string $expected): void
     {
         foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /* MichelfMarkdown::class, */ DefaultMarkdown::class] as $class) {
             $twig = new Environment(new ArrayLoader([
diff --git a/extra/markdown-extra/Tests/LegacyFunctionsTest.php b/extra/markdown-extra/Tests/LegacyFunctionsTest.php
index 19a861d..c3a8708 100644
--- a/extra/markdown-extra/Tests/LegacyFunctionsTest.php
+++ b/extra/markdown-extra/Tests/LegacyFunctionsTest.php
@@ -11,6 +11,7 @@
 
 namespace Twig\Extra\Markdown\Tests;
 
+use PHPUnit\Framework\Attributes\IgnoreDeprecations;
 use PHPUnit\Framework\TestCase;
 
 use function Twig\Extra\Markdown\html_to_markdown;
@@ -22,6 +23,7 @@ use Twig\Extra\Markdown\MarkdownExtension;
  */
 class LegacyFunctionsTest extends TestCase
 {
+    #[IgnoreDeprecations]
     public function testHtmlToMarkdown()
     {
         $this->assertSame(MarkdownExtension::htmlToMarkdown('<p>foo</p>'), html_to_markdown('<p>foo</p>'));
diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php
index fb9090c..4526808 100644
--- a/tests/EnvironmentTest.php
+++ b/tests/EnvironmentTest.php
@@ -435,11 +435,9 @@ class EnvironmentTest extends TestCase
         $this->assertSame('dynamic', $parser->getTag());
     }
 
-    /**
-     * @group legacy
-     *
-     * @requires PHP 8
-     */
+    #[\PHPUnit\Framework\Attributes\RequiresPhp('8')]
+    #[\PHPUnit\Framework\Attributes\Group('legacy')]
+    #[\PHPUnit\Framework\Attributes\Group('nophpunit12')]
     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 35afbe8..c54011c 100644
--- a/tests/ErrorTest.php
+++ b/tests/ErrorTest.php
@@ -259,9 +259,7 @@ EOHTML,
         }
     }
 
-    /**
-     * @dataProvider getErrorWithoutLineAndContextData
-     */
+    #[\PHPUnit\Framework\Attributes\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 5e60dfc..d527840 100644
--- a/tests/ExpressionParserTest.php
+++ b/tests/ExpressionParserTest.php
@@ -471,9 +471,8 @@ class ExpressionParserTest extends TestCase
         $this->expectNotToPerformAssertions();
     }
 
-    /**
-     * @group legacy
-     */
+    #[\PHPUnit\Framework\Attributes\Group('legacy')]
+    #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
     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.');
@@ -486,9 +485,8 @@ class ExpressionParserTest extends TestCase
         $parser->parse($env->tokenize(new Source('{{ foo() }}', 'index')));
     }
 
-    /**
-     * @group legacy
-     */
+    #[\PHPUnit\Framework\Attributes\Group('legacy')]
+    #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
     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.');
@@ -501,9 +499,8 @@ class ExpressionParserTest extends TestCase
         $parser->parse($env->tokenize(new Source('{{ 1|foo }}', 'index')));
     }
 
-    /**
-     * @group legacy
-     */
+    #[\PHPUnit\Framework\Attributes\Group('legacy')]
+    #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
     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.');
@@ -581,9 +578,7 @@ class ExpressionParserTest extends TestCase
         $this->expectNotToPerformAssertions();
     }
 
-    /**
-     * @dataProvider getBindingPowerTests
-     */
+    #[\PHPUnit\Framework\Attributes\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 68e3bfe..34e3161 100644
--- a/tests/Extension/AttributeExtensionTest.php
+++ b/tests/Extension/AttributeExtensionTest.php
@@ -16,9 +16,7 @@ use Twig\TwigTest;
 
 class AttributeExtensionTest extends TestCase
 {
-    /**
-     * @dataProvider provideFilters
-     */
+    #[\PHPUnit\Framework\Attributes\DataProvider('provideFilters')]
     public function testFilter(string $name, string $method, array $options)
     {
         $extension = new AttributeExtension(ExtensionWithAttributes::class);
@@ -44,9 +42,7 @@ class AttributeExtensionTest extends TestCase
         yield 'pattern' => ['pattern_*_filter', 'patternFilter', []];
     }
 
-    /**
-     * @dataProvider provideFunctions
-     */
+    #[\PHPUnit\Framework\Attributes\DataProvider('provideFunctions')]
     public function testFunction(string $name, string $method, array $options)
     {
         $extension = new AttributeExtension(ExtensionWithAttributes::class);
@@ -72,9 +68,7 @@ class AttributeExtensionTest extends TestCase
         yield 'deprecated' => ['deprecated_function', 'deprecatedFunction', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]];
     }
 
-    /**
-     * @dataProvider provideTests
-     */
+    #[\PHPUnit\Framework\Attributes\DataProvider('provideTests')]
     public function testTest(string $name, string $method, array $options)
     {
         $extension = new AttributeExtension(ExtensionWithAttributes::class);
diff --git a/tests/Extension/EscaperTest.php b/tests/Extension/EscaperTest.php
index 28df82d..7b59644 100644
--- a/tests/Extension/EscaperTest.php
+++ b/tests/Extension/EscaperTest.php
@@ -11,6 +11,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\Extension\EscaperExtension;
@@ -24,6 +25,7 @@ class EscaperTest extends TestCase
      *
      * @group legacy
      */
+    #[DataProvider('provideCustomEscaperCases')]
     public function testCustomEscaper($expected, $string, $strategy)
     {
         $twig = new Environment(new ArrayLoader());
@@ -46,6 +48,7 @@ class EscaperTest extends TestCase
      *
      * @group legacy
      */
+    #[DataProvider('provideCustomEscaperCases')]
     public function testCustomEscaperWithoutCallingSetEscaperRuntime($expected, $string, $strategy)
     {
         $twig = new Environment(new ArrayLoader());
diff --git a/tests/Extension/SandboxTest.php b/tests/Extension/SandboxTest.php
index fd655f7..beb40fe 100644
--- a/tests/Extension/SandboxTest.php
+++ b/tests/Extension/SandboxTest.php
@@ -111,11 +111,9 @@ class SandboxTest extends TestCase
         yield ['with', '{% with foo %}{% endwith %}'];
     }
 
-    /**
-     * @dataProvider getSandboxedForExtendsAndUseTagsTests
-     *
-     * @group legacy
-     */
+    #[DataProvider('getSandboxedForExtendsAndUseTagsTests')]
+    #[\PHPUnit\Framework\Attributes\Group('legacy')]
+    #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
     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.', $tag));
@@ -174,9 +172,7 @@ class SandboxTest extends TestCase
         }
     }
 
-    /**
-     * @group legacy
-     */
+    #[\PHPUnit\Framework\Attributes\Group('legacy')]
     public function testIfSandBoxIsDisabledAfterSyntaxErrorLegacy()
     {
         $twig = $this->getEnvironment(false, [], self::$templates);
diff --git a/tests/LexerTest.php b/tests/LexerTest.php
index a22a2fb..3f62c91 100644
--- a/tests/LexerTest.php
+++ b/tests/LexerTest.php
@@ -249,6 +249,7 @@ class LexerTest extends TestCase
      *
      * @dataProvider getStringWithEscapedDelimiterProducingDeprecation
      */
+    #[DataProvider('getStringWithEscapedDelimiterProducingDeprecation')]
     public function testStringWithEscapedDelimiterProducingDeprecation(string $template, string $expected, string $expectedDeprecation)
     {
         $this->expectDeprecation($expectedDeprecation);
@@ -615,6 +616,7 @@ bar
     /**
      * @dataProvider getTemplateForUnclosedBracketInExpression
      */
+    #[DataProvider('getTemplateForUnclosedBracketInExpression')]
     public function testUnclosedBracketInExpression(string $template, string $bracket)
     {
         $lexer = new Lexer(new Environment(new ArrayLoader()));
@@ -636,6 +638,7 @@ bar
     /**
      * @dataProvider getTemplateForUnexpectedBracketInExpression
      */
+    #[DataProvider('getTemplateForUnexpectedBracketInExpression')]
     public function testUnexpectedBracketInExpression(string $template, string $bracket)
     {
         $lexer = new Lexer(new Environment(new ArrayLoader()));
diff --git a/tests/NodeVisitor/OptimizerTest.php b/tests/NodeVisitor/OptimizerTest.php
index b765b48..fd00624 100644
--- a/tests/NodeVisitor/OptimizerTest.php
+++ b/tests/NodeVisitor/OptimizerTest.php
@@ -56,6 +56,7 @@ class OptimizerTest extends TestCase
         $this->assertTrue($node->getAttribute('output'));
     }
 
+    #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
     public function testForVarOptimizer()
     {
         $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php
index afe2882..a9bc20b 100644
--- a/tests/TemplateTest.php
+++ b/tests/TemplateTest.php
@@ -202,7 +202,7 @@ class TemplateTest extends TestCase
     }
 
     #[DataProvider('getGetAttributeTests')]
-    public function testGetAttribute($defined, $value, $object, $item, $arguments, $type)
+    public function testGetAttribute($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null)
     {
         $twig = new Environment(new ArrayLoader());
         $template = new TemplateForTest($twig);
@@ -228,7 +228,7 @@ class TemplateTest extends TestCase
     }
 
     #[DataProvider('getGetAttributeTests')]
-    public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type)
+    public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null)
     {
         $twig = new Environment(new ArrayLoader());
         $template = new TemplateForTest($twig);
@@ -237,7 +237,7 @@ class TemplateTest extends TestCase
     }
 
     #[DataProvider('getGetAttributeTests')]
-    public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type)
+    public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null)
     {
         $twig = new Environment(new ArrayLoader(), ['strict_variables' => true]);
         $template = new TemplateForTest($twig);
