PHPCSStandards / composer-installer

Composer installer for PHP_CodeSniffer coding standards
https://packagist.org/packages/dealerdirect/phpcodesniffer-composer-installer
MIT License
549 stars 36 forks source link

Tests: add new `PreexistingPHPCSInstalledPathsConfigTest` + bug fix #167

Closed jrfnl closed 2 years ago

jrfnl commented 2 years ago

Proposed Changes

Tests: add new PreexistingPHPCSInstalledPathsConfigTest

This new test class tests that the plugin handles a pre-existing PHPCS configuration file, which includes an installed_paths setting, correctly.

These tests verify:

Notes:

Plugin: add new getPhpcsCommand() method (bug fix)

PR #80 in response to bug #79 fixed the issue of the command to set the installed paths failing when the system default PHP version was being used instead of the PHP version used by Composer.

However, PHPCS is also called for the --config-show command to retrieve the originally set paths as well as to verify a successful save.

This --config-show command was not adjusted at the time and was still being run using the system default PHP version, which could lead to valid installed_paths which were present before the installation of the plugin being removed, as --config-show would silently fail, leading to the initial $this->installedPaths being empty.

This commit fixes that by:

  1. Introducing a new getPhpcsCommand() method which will cobble together the PHP executable + the PHPCS executable to a runnable command.
  2. Using that new method in both places in the plugin were PHPCS is called.

This fixes the bug and improves consistency in the plugin.

It also happens to work as a work-around for upstream by composer/composer#10504 as it removes the call to $this->composer->getConfig()->get('bin-dir') which would result in an incorrect execution directory on Windows with Composer 2.2.2 - 2.2.5 (a fix for the issues was included in Composer itself in release 2.2.6).

Related to #92