Skip to content

Commit 9aea66e

Browse files
committed
do not patch the TestCase class with PHPUnit 10+
1 parent 9d89e05 commit 9aea66e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
}
144144
}
145145

146-
if ('disabled' === $getEnvVar('SYMFONY_DEPRECATIONS_HELPER')) {
146+
if ('disabled' === $getEnvVar('SYMFONY_DEPRECATIONS_HELPER') || version_compare($PHPUNIT_VERSION, '11', '>=')) {
147147
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
148148
}
149149

@@ -273,19 +273,20 @@
273273
}
274274

275275
// 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);
276+
if (version_compare($PHPUNIT_VERSION, '10', '<')) {
277+
$alteredCode = file_get_contents($alteredFile = './src/Framework/TestCase.php');
278+
if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) {
279+
$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode);
280+
}
281+
$alteredCode = preg_replace('/abstract class TestCase[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillTestCaseTrait;", $alteredCode, 1);
282+
file_put_contents($alteredFile, $alteredCode);
282283

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);
284+
// Mutate Assert code
285+
$alteredCode = file_get_contents($alteredFile = './src/Framework/Assert.php');
286+
$alteredCode = preg_replace('/abstract class Assert[^\{]+\{/', '$0 '.\PHP_EOL." use \Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait;", $alteredCode, 1);
287+
file_put_contents($alteredFile, $alteredCode);
287288

288-
file_put_contents('phpunit', <<<'EOPHP'
289+
file_put_contents('phpunit', <<<'EOPHP'
289290
<?php
290291
291292
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
@@ -310,7 +311,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
310311
Symfony\Bridge\PhpUnit\TextUI\Command::main();
311312

312313
EOPHP
313-
);
314+
);
315+
}
316+
314317
chdir('..');
315318
file_put_contents(".$PHPUNIT_VERSION_DIR.md5", $configurationHash);
316319
chdir($oldPwd);

0 commit comments

Comments
 (0)