Skip to content

Commit be6469b

Browse files
committed
When using phpenv + phpenv-composer plugin, composer executable is wrapped into bash script, checking that detect composer is binary
1 parent 4b419f2 commit be6469b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ foreach ($defaultEnvs as $envName => $envValue) {
5757
}
5858
}
5959

60+
$isWindows = '\\' === DIRECTORY_SEPARATOR;
6061
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar')
61-
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
62-
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`))
63-
? $PHP.' '.escapeshellarg($COMPOSER)
62+
|| ($COMPOSER = rtrim($isWindows ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
63+
|| ($COMPOSER = rtrim($isWindows ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`))
64+
? (!$isWindows && (strpos(`file $COMPOSER 2> /dev/null`, 'binary data') === false) ? '' : $PHP).' '.escapeshellarg($COMPOSER)
6465
: 'composer';
6566

6667
if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) {
@@ -73,9 +74,9 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
7374
@mkdir($PHPUNIT_DIR, 0777, true);
7475
chdir($PHPUNIT_DIR);
7576
if (file_exists("phpunit-$PHPUNIT_VERSION")) {
76-
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s > NUL': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
77+
passthru(sprintf($isWindows ? 'rmdir /S /Q %s > NUL': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
7778
rename("phpunit-$PHPUNIT_VERSION", "phpunit-$PHPUNIT_VERSION.old");
78-
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
79+
passthru(sprintf($isWindows ? 'rmdir /S /Q %s': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION.old"));
7980
}
8081
passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit phpunit-$PHPUNIT_VERSION \"$PHPUNIT_VERSION.*\"");
8182
@copy("phpunit-$PHPUNIT_VERSION/phpunit.xsd", 'phpunit.xsd');
@@ -91,15 +92,15 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
9192
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
9293
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
9394
passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
94-
if ('\\' === DIRECTORY_SEPARATOR) {
95+
if ($isWindows) {
9596
file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
9697
}
9798
} else {
9899
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
99100
}
100101
$prevRoot = getenv('COMPOSER_ROOT_VERSION');
101102
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
102-
$q = '\\' === DIRECTORY_SEPARATOR ? '"' : '';
103+
$q = $isWindows ? '"' : '';
103104
// --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS
104105
$exit = proc_close(proc_open("$q$COMPOSER install --no-dev --prefer-dist --no-progress --ansi$q", array(), $p, getcwd()));
105106
putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
@@ -171,7 +172,7 @@ if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.d
171172
$cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
172173
$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
173174

174-
if ('\\' === DIRECTORY_SEPARATOR) {
175+
if ($isWindows) {
175176
$cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
176177
} else {
177178
$cmd .= '%2$s';

0 commit comments

Comments
 (0)