Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PHPUnit 11 #4477

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/Test/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand All @@ -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 = [];

Expand Down
13 changes: 12 additions & 1 deletion src/Test/NodeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading