Skip to content

Commit 0438baa

Browse files
committed
bug symfony#36882 [PhpUnitBridge] fix installing under PHP >= 8 (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [PhpUnitBridge] fix installing under PHP >= 8 | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - [As experimented on Twig](twigphp/Twig@b952011), using `simple-phpunit` is not simple enough when testing with PHP 8. This PR fixes the issue so that we could remove these lines in Twig. On 3.4 since supporting new versions of PHP is a bugfix according to our policies. Commits ------- 5aa25ce [PhpUnitBridge] fix installing under PHP >= 8
2 parents 5fc4d1b + 5aa25ce commit 0438baa

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
8787
rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old");
8888
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
8989
}
90+
91+
$info = array();
92+
foreach (explode("\n", `$COMPOSER info -a -n phpunit/phpunit "$PHPUNIT_VERSION.*"`) as $line) {
93+
$line = rtrim($line);
94+
95+
if (!$info && preg_match('/^versions +: /', $line)) {
96+
$info['versions'] = explode(', ', ltrim(substr($line, 9), ': '));
97+
} elseif (isset($info['requires'])) {
98+
if ('' === $line) {
99+
break;
100+
}
101+
102+
$line = explode(' ', $line, 2);
103+
$info['requires'][$line[0]] = $line[1];
104+
} elseif ($info && 'requires' === $line) {
105+
$info['requires'] = array();
106+
}
107+
}
108+
109+
if (1 === \count($info['versions'])) {
110+
$passthruOrFail("$COMPOSER create-project --ignore-platform-reqs --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi -s dev phpunit/phpunit $PHPUNIT_VERSION_DIR \"$PHPUNIT_VERSION.*\"");
111+
} else {
112+
$passthruOrFail("$COMPOSER create-project --ignore-platform-reqs --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit $PHPUNIT_VERSION_DIR \"$PHPUNIT_VERSION.*\"");
113+
}
114+
90115
$passthruOrFail("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
91116
@copy("phpunit-$PHPUNIT_VERSION/phpunit.xsd", 'phpunit.xsd');
92117
chdir("phpunit-$PHPUNIT_VERSION");
@@ -97,6 +122,9 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
97122
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
98123
}
99124

125+
if ($info['requires']['php'] !== $phpVersion = preg_replace('{\^([\d\.]++)$}', '>=$1', $info['requires']['php'])) {
126+
$passthruOrFail("$COMPOSER require --no-update \"php:$phpVersion\"");
127+
}
100128
$passthruOrFail("$COMPOSER config --unset platform.php");
101129
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
102130
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");

0 commit comments

Comments
 (0)