Skip to content

Commit 2faee18

Browse files
committed
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.
1 parent 676fcfa commit 2faee18

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Diff for: bin/simple-phpunit.php

+21-13
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
$PHPUNIT_VERSION = $MAX_PHPUNIT_VERSION;
110110
}
111111

112+
if (version_compare($PHPUNIT_VERSION, '10.0', '>=') && version_compare($PHPUNIT_VERSION, '11.0', '<')) {
113+
fwrite(STDERR, 'This script does not work with PHPUnit 10.'.\PHP_EOL);
114+
exit(1);
115+
}
116+
112117
$PHPUNIT_REMOVE_RETURN_TYPEHINT = filter_var($getEnvVar('SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT', '0'), \FILTER_VALIDATE_BOOLEAN);
113118

114119
$COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json';
@@ -143,7 +148,7 @@
143148
}
144149
}
145150

146-
if ('disabled' === $getEnvVar('SYMFONY_DEPRECATIONS_HELPER')) {
151+
if ('disabled' === $getEnvVar('SYMFONY_DEPRECATIONS_HELPER') || version_compare($PHPUNIT_VERSION, '11.0', '>=')) {
147152
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
148153
}
149154

@@ -273,19 +278,20 @@
273278
}
274279

275280
// Mutate TestCase code
276-
$alteredCode = file_get_contents($alteredFile = './src/Framework/TestCase.php');
277-
if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) {
278-
$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode);
279-
}
280-
$alteredCode = preg_replace('/abstract class TestCase[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1);
281-
file_put_contents($alteredFile, $alteredCode);
281+
if (version_compare($PHPUNIT_VERSION, '11.0', '<')) {
282+
$alteredCode = file_get_contents($alteredFile = './src/Framework/TestCase.php');
283+
if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) {
284+
$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode);
285+
}
286+
$alteredCode = preg_replace('/abstract class TestCase[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1);
287+
file_put_contents($alteredFile, $alteredCode);
282288

283-
// Mutate Assert code
284-
$alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php');
285-
$alteredCode = preg_replace('/abstract class Assert[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1);
286-
file_put_contents($alteredFile, $alteredCode);
289+
// Mutate Assert code
290+
$alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php');
291+
$alteredCode = preg_replace('/abstract class Assert[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1);
292+
file_put_contents($alteredFile, $alteredCode);
287293

288-
file_put_contents('phpunit', <<<'EOPHP'
294+
file_put_contents('phpunit', <<<'EOPHP'
289295
<?php
290296
291297
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
@@ -310,7 +316,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
310316
Symfony\Bridge\PhpUnit\TextUI\Command::main();
311317

312318
EOPHP
313-
);
319+
);
320+
}
321+
314322
chdir('..');
315323
file_put_contents(".$PHPUNIT_VERSION_DIR.md5", $configurationHash);
316324
chdir($oldPwd);

0 commit comments

Comments
 (0)