Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: add new PreexistingPHPCSInstalledPathsConfigTest + bug fix #167

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 5, 2022

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:

  • That the plugin does not remove or alter any valid paths which already existed in installed_paths.
  • That the plugin removes invalid paths which already existed in installed_paths.

Notes:

  • While PHPCS behaves the same whether installed locally or globally, it is still necessary to run the tests in both type of environments.
    Bug [2.2.2+] $this->composer->getConfig()->get('bin-dir') returns incorrect path on Windows composer/composer#10504 (discovered while writing these tests) is example of the reason why.
    To not create too much redundancy, I've elected to run one of the tests via Composer global and the other one via local.
  • As the output of the config-show command in PHPCS has changed across PHPCS version, it is necessary to test against multiple PHPCS versions.

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

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:
- That the plugin does not remove or alter any valid paths which already existed in `installed_paths`.
- That the plugin removes invalid paths which already existed in `installed_paths`.

Notes:
* While PHPCS behaves the same whether installed locally or globally, it is still necessary to run the tests in both type of environments.
    Bug composer/composer 10504 (discovered while writing these tests) is example of the reason why.
    To not create too much redundancy, I've elected to run one of the tests via Composer global and the other one via local.
* As the output of the `config-show` command in PHPCS has changed across PHPCS version, it is necessary to test against multiple PHPCS versions.
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+.
@jrfnl jrfnl force-pushed the feature/tests-new-preexistingphpcsinstalledpathsconfig-test branch from 9109ff4 to c01bd6f Compare March 5, 2022 19:45
@Potherca Potherca merged commit 30297a0 into master Apr 18, 2022
@Potherca Potherca deleted the feature/tests-new-preexistingphpcsinstalledpathsconfig-test branch April 18, 2022 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants