Skip to content

[2.2.2+] $this->composer->getConfig()->get('bin-dir') returns incorrect path on Windows #10504

@jrfnl

Description

@jrfnl

Context

I'm currently in the process of writing End-to-End tests for the DealerDirect PHPCS Composer Installer plugin and discovered the following due to tests failing.

Problem description

In the plugin we call PHPCS using the following code, which should be executed either in the Composer global or the project local directory, depending on the context in which a Composer install/update is being run:

$this->processExecutor->execute(
    'phpcs --config-show',
    $output,
    $this->composer->getConfig()->get('bin-dir')
);

This used to work correctly in all cases, but since Composer 2.2.2, it appears to be broken on Windows (server).

Based on my debugging:

  • Ubuntu is not affected.
  • The issue exists independently of the PHP version used to run Composer (tested with PHP 5.4, 7.2 and 8.1).

Output of $this->composer->getConfig()->get('bin-dir') for Composer < 2.2.2 on Windows (via GitHub actions)

This output is correct and as expected:

  • Global install:
    • Ubuntu: /tmp/PHPCSPluginTest/PreexistingPHPCSInstalledPathsConfigTest_61fa7843f015f2.37374271/global/vendor/bin
    • Windows: C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\PHPCSPluginTest\\PreexistingPHPCSInstalledPathsConfigTest_61fa786d7645e1.82846304\\global/vendor/bin
  • Project local install:
    • Ubuntu: /tmp/PHPCSPluginTest/PreexistingPHPCSInstalledPathsConfigTest_61fa784784d707.70495208/local/vendor/bin
    • Windows: C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\PHPCSPluginTest\\PreexistingPHPCSInstalledPathsConfigTest_61fa787cb36404.36256677\\local/vendor/bin

Output of $this->composer->getConfig()->get('bin-dir') for Composer 2.2.2 up to snapshot on Windows (via GitHub actions)

This output is wrong for Windows, correct for Ubuntu:

  • Global install:
    • Ubuntu: /tmp/PHPCSPluginTest/PreexistingPHPCSInstalledPathsConfigTest_61fa783fcdb903.30230172/global/vendor/bin
    • Windows: D:\\a\\phpcodesniffer-composer-installer\\phpcodesniffer-composer-installer\\vendor\\bin
  • Project local install:
    • Ubuntu: /tmp/PHPCSPluginTest/PreexistingPHPCSInstalledPathsConfigTest_61fa7842c99229.60312001/local/vendor/bin
    • Windows: D:\\a\\phpcodesniffer-composer-installer\\phpcodesniffer-composer-installer\\vendor\\bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions