Skip to content
Merged
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
34 changes: 21 additions & 13 deletions src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fwrite(STDERR, 'This script does not work with PHPUnit 10.'.\PHP_EOL);
fwrite(STDERR, 'The simple-phpunit script does not work with PHPUnit 10.'.\PHP_EOL);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this because when you install the bridge the recipe will create a bin/phpunit file which one will run. So no pointer about a simple-phpunit script. My guess was that this is also the reason why the check on line 16 also talks about "This script".

exit(1);
}

$PHPUNIT_REMOVE_RETURN_TYPEHINT = filter_var($getEnvVar('SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT', '0'), \FILTER_VALIDATE_BOOLEAN);

$COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json';
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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'
<?php

define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
Expand All @@ -310,7 +316,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
Symfony\Bridge\PhpUnit\TextUI\Command::main();

EOPHP
);
);
}

chdir('..');
file_put_contents(".$PHPUNIT_VERSION_DIR.md5", $configurationHash);
chdir($oldPwd);
Expand Down