Closed
Description
Symfony version(s) affected: >= 4.4
Description
#41780 re-introduced the use of COMPOSER_BINARY
.
This breaks execution when using PowerShell
COMPOSER_BINARY
resolves to "C:\ProgramData\ComposerSetup\bin\composer.phar" on my system- Windows does not know how to execute phar files and asks for a program to open .phar files with
This shows the difference to the old behavior on Windows:
Change vendor\symfony\phpunit-bridge\bin\simple-phpunit.php
+var_dump(getenv('COMPOSER_BINARY'));
+
- if (false === $COMPOSER = getenv('COMPOSER_BINARY')) {
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar')
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar 2> NUL`) : `which composer.phar 2> /dev/null`)))
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer 2> NUL`) : `which composer 2> /dev/null`)))
|| file_exists($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? `git rev-parse --show-toplevel 2> NUL` : `git rev-parse --show-toplevel 2> /dev/null`)).\DIRECTORY_SEPARATOR.'composer.phar')
? ('#!/usr/bin/env php' === file_get_contents($COMPOSER, false, null, 0, 18) ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
: 'composer';
- }
+
+var_dump($COMPOSER);
+
+die;
Produces:
string(46) "C:\ProgramData\ComposerSetup\bin\composer.phar"
string(79) ""C:\tools\php\current\php.exe" "C:\ProgramData\ComposerSetup\bin\composer.phar""
How to reproduce
Use symfony/phpunit-bridge on Windows within a Symfony >= 5.2 project and run php bin/phpunit
in PowerShell.
Possible Solution
Resolve composer as so:
$COMPOSER = ($COMPOSER = getenv('COMPOSER_BINARY'))
|| file_exists($COMPOSER = $oldPwd.'/composer.phar')
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar 2> NUL`) : `which composer.phar 2> /dev/null`)))
|| ($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer 2> NUL`) : `which composer 2> /dev/null`)))
|| file_exists($COMPOSER = rtrim((string) ('\\' === \DIRECTORY_SEPARATOR ? `git rev-parse --show-toplevel 2> NUL` : `git rev-parse --show-toplevel 2> /dev/null`)).\DIRECTORY_SEPARATOR.'composer.phar')
? ('#!/usr/bin/env php' === file_get_contents($COMPOSER, false, null, 0, 18) ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
: 'composer';