diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php index 8c9d41f2a44..dc3687900b4 100644 --- a/src/Test/IntegrationTestCase.php +++ b/src/Test/IntegrationTestCase.php @@ -11,6 +11,9 @@ namespace Twig\Test; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Twig\Environment; use Twig\Error\Error; @@ -85,23 +88,55 @@ protected function getTwigTests() } /** + * @requires PHPUnit < 11 * @dataProvider getTests */ + #[RequiresPhpunit('< 11'), DataProvider('getTests')] public function testIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') { $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); } /** + * @requires PHPUnit < 11 * @dataProvider getLegacyTests * * @group legacy */ + #[RequiresPhpunit('< 11'), DataProvider('getLegacyTests'), Group('legacy')] public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') { $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); } + /** + * @requires PHPUnit >= 11 + */ + #[RequiresPhpunit('>= 11'), DataProvider('provideTests')] + public function testIntegrationTests($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); + } + + /** + * @requires PHPUnit >= 11 + */ + #[RequiresPhpunit('>= 11'), DataProvider('provideLegacyTests'), Group('legacy')] + public function testLegacyIntegrationTests($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') + { + $this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs, $deprecation); + } + + final public static function provideTests(): iterable + { + return self::assembleTests(false, static::getFixturesDirectory()); + } + + final public static function provideLegacyTests(): iterable + { + return self::assembleTests(true, static::getFixturesDirectory()); + } + /** * @final since Twig 3.13 */ @@ -114,6 +149,11 @@ public function getTests($name, $legacyTests = false) $fixturesDir = $this->getFixturesDir(); } + return self::assembleTests($legacyTests, $fixturesDir); + } + + private static function assembleTests(bool $legacyTests, string $fixturesDir): array + { $fixturesDir = realpath($fixturesDir); $tests = []; diff --git a/src/Test/NodeTestCase.php b/src/Test/NodeTestCase.php index bac0ea6d036..4b0322156f3 100644 --- a/src/Test/NodeTestCase.php +++ b/src/Test/NodeTestCase.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\Attributes\BeforeClass; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpunit; use PHPUnit\Framework\TestCase; use Twig\Compiler; use Twig\Environment; @@ -42,15 +43,25 @@ public static function provideTests(): iterable } /** + * @requires PHPUnit < 11 * @dataProvider getTests * @dataProvider provideTests */ - #[DataProvider('getTests'), DataProvider('provideTests')] + #[RequiresPhpunit('< 11'), DataProvider('getTests'), DataProvider('provideTests')] public function testCompile($node, $source, $environment = null, $isPattern = false) { $this->assertNodeCompilation($source, $node, $environment, $isPattern); } + /** + * @requires PHPUnit >= 11 + */ + #[RequiresPhpunit('>= 11'), DataProvider('provideTests')] + public function testNodeCompile($node, $source, $environment = null, $isPattern = false) + { + $this->assertNodeCompilation($source, $node, $environment, $isPattern); + } + public function assertNodeCompilation($source, Node $node, ?Environment $environment = null, $isPattern = false) { $compiler = $this->getCompiler($environment);