From eb427168227aa945ad4faf4f00c093243d48e8c6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 15 Oct 2024 12:42:42 +0200 Subject: [PATCH] do not patch the TestCase class with PHPUnit 11+ The PHPUnit\TextUI\Command class was removed in PHPUnit 10. Since the sole purpose of the class extended the base Command class is to register a the Symfony test listener we can completely stop patching it as support for the listener-based event system was also removed in PHPUnit 10. --- .../Bridge/PhpUnit/bin/simple-phpunit.php | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php index bd07a218c49ab..0472e8c1d81b3 100644 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php @@ -109,6 +109,11 @@ $PHPUNIT_VERSION = $MAX_PHPUNIT_VERSION; } +if (version_compare($PHPUNIT_VERSION, '10.0', '>=') && version_compare($PHPUNIT_VERSION, '11.0', '<')) { + fwrite(STDERR, 'This script does not work with PHPUnit 10.'.\PHP_EOL); + exit(1); +} + $PHPUNIT_REMOVE_RETURN_TYPEHINT = filter_var($getEnvVar('SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT', '0'), \FILTER_VALIDATE_BOOLEAN); $COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json'; @@ -143,7 +148,7 @@ } } -if ('disabled' === $getEnvVar('SYMFONY_DEPRECATIONS_HELPER')) { +if ('disabled' === $getEnvVar('SYMFONY_DEPRECATIONS_HELPER') || version_compare($PHPUNIT_VERSION, '11.0', '>=')) { putenv('SYMFONY_DEPRECATIONS_HELPER=disabled'); } @@ -273,19 +278,20 @@ } // Mutate TestCase code - $alteredCode = file_get_contents($alteredFile = './src/Framework/TestCase.php'); - if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) { - $alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode); - } - $alteredCode = preg_replace('/abstract class TestCase[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1); - file_put_contents($alteredFile, $alteredCode); + if (version_compare($PHPUNIT_VERSION, '11.0', '<')) { + $alteredCode = file_get_contents($alteredFile = './src/Framework/TestCase.php'); + if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) { + $alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode); + } + $alteredCode = preg_replace('/abstract class TestCase[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1); + file_put_contents($alteredFile, $alteredCode); - // Mutate Assert code - $alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php'); - $alteredCode = preg_replace('/abstract class Assert[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1); - file_put_contents($alteredFile, $alteredCode); + // Mutate Assert code + $alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php'); + $alteredCode = preg_replace('/abstract class Assert[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1); + file_put_contents($alteredFile, $alteredCode); - file_put_contents('phpunit', <<<'EOPHP' + file_put_contents('phpunit', <<<'EOPHP'