Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[PhpUnitBridge] Broken COMPOSER_BINARY on Windows #42129

Copy link
Copy link
Closed
@Rainrider

Description

@Rainrider
Issue body actions

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';

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.