diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index b94016f5..00000000 --- a/.editorconfig +++ /dev/null @@ -1,21 +0,0 @@ -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_style = space -insert_final_newline = true -trim_trailing_whitespace = true - -[*.php] -ident_size = 4 - -[*.md] -ident_size = 2 -trim_trailing_whitespace = false - -[*.json] -ident_size = 2 - -[{.gitignore,.gitkeep,.editorconfig}] -ident_size = 2 diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 381a15b5..00000000 --- a/.gitattributes +++ /dev/null @@ -1,18 +0,0 @@ -# Ignore files for distribution archives. - -.editorconfig export-ignore -.gitattributes export-ignore -.github_changelog_generator export-ignore -.gitignore export-ignore -.remarkrc export-ignore -.yamllint export-ignore - -CODE_OF_CONDUCT.md export-ignore -CONTRIBUTING.md export-ignore -phpcs.xml.dist export-ignore -phpunit.xml.dist export-ignore - -# Ignore directories for distribution archives. -/.github/ export-ignore -/bin/ export-ignore -/tests/ export-ignore diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 98c31ca0..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve - ---- - -## Problem/Motivation - -> (Why the issue was filed) - -## Expected behaviour - -> (What you expected to happen) - -## Actual behaviour - -> (What actually happened) - -## Steps to reproduce - -> (How can someone else make/see it happen) -> -> (Please include any relevant links. Think: links to a branch in a repo where you are experiencing the problem -> which can be used to reproduce the issue, links to external standards you are using.) -> (Also, if relevant and if it can be used to reproduce the issue, please paste the contents of your `composer.json` -> file here. -> -> ```json -> (Content of the `composer.json` file) -> ``` - -## Proposed changes - -> (If you have a proposed change, workaround or fix, describe the rationale behind it) - -## Environment - -| Question | Answer -| ----------------------------- | ------- -| OS | Windows/Linux/Mac (preferably with some version info) -| PHP version | x.y.z -| Composer version | x.y.z -| PHP_CodeSniffer version | x.y.z -| Composer PHPCS plugin version | x.y.z -| Install type | e.g. Composer global, Composer project local, other (please expand) - -Output of `vendor/bin/phpcs --config-show`: -``` -(Please paste the output you get here) -``` - -## Tested against `master` branch? -- [ ] I have verified the issue still exists in the `master` branch. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 57fcd540..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ -## Proposed Changes - -> (Describe the changes and rationale behind them) - -## Related Issues - -> ([Github link](https://help.github.com/articles/autolinked-references-and-urls/) to related issues or pull requests) diff --git a/.github/workflows/integrationtest.yml b/.github/workflows/integrationtest.yml deleted file mode 100644 index 078733c7..00000000 --- a/.github/workflows/integrationtest.yml +++ /dev/null @@ -1,150 +0,0 @@ ---- -name: Integration Test - -on: - # Run on pushes to `master` and on all pull requests. - push: - branches: - - master - pull_request: - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - runs-on: "${{ matrix.os }}" - - strategy: - matrix: - php: - - '5.4' - - '5.5' - - '5.6' - - '7.0' - - '7.1' - - '7.2' - - '7.3' - - '7.4' - - '8.0' - - '8.1' - - '8.2' - - '8.3' - composer: - - 'v1' - - 'v2' - os: - - 'ubuntu-latest' - - 'windows-latest' - - exclude: - # Exclude a particularly problematic build. - # @link https://github.com/PHPCSStandards/composer-installer/issues/181 - - php: '5.5' - composer: 'v1' - os: 'windows-latest' - - include: - # Composer 2.3 drops support for PHP < 7.2, so for PHP 5.4 to 7.1, `v2` will install - # Composer 2.2, for PHP 7.2 and up, `v2` will install Composer 2.3. - # These builds make sure the Composer 2.2 LTS version is 100% supported for PHP 7.2-8.x. - - php: '7.2' - composer: '2.2' - os: 'ubuntu-latest' - - php: '7.3' - composer: '2.2' - os: 'ubuntu-latest' - - php: '7.4' - composer: '2.2' - os: 'ubuntu-latest' - - php: '8.0' - composer: '2.2' - os: 'ubuntu-latest' - - php: '8.1' - composer: '2.2' - os: 'ubuntu-latest' - - php: '8.2' - composer: '2.2' - os: 'ubuntu-latest' - - php: '8.3' - composer: '2.2' - os: 'ubuntu-latest' - - - php: '7.2' - composer: '2.2' - os: 'windows-latest' - - php: '7.3' - composer: '2.2' - os: 'windows-latest' - - php: '7.4' - composer: '2.2' - os: 'windows-latest' - - php: '8.0' - composer: '2.2' - os: 'windows-latest' - - php: '8.1' - composer: '2.2' - os: 'windows-latest' - - php: '8.2' - composer: '2.2' - os: 'windows-latest' - - php: '8.3' - composer: '2.2' - os: 'windows-latest' - - # Also test against the dev version of Composer for early warning about upcoming changes. - - php: 'latest' - composer: 'snapshot' - os: 'ubuntu-latest' - - - php: 'latest' - composer: 'snapshot' - os: 'windows-latest' - - name: "Integration test" - - continue-on-error: ${{ matrix.php == '8.3' || matrix.composer == 'snapshot' }} - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: json, zip - ini-values: zend.assertions=1, error_reporting=-1, display_errors=On - tools: "composer:${{ matrix.composer }}" - coverage: none - env: - fail-fast: true - - - name: "Conditionally disable tls (Composer 1.x/Windows/PHP 5.4)" - if: ${{ matrix.os == 'windows-latest' && matrix.composer == 'v1' && matrix.php == '5.4' }} - run: composer config -- disable-tls true - - # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies - - name: Install Composer dependencies - if: ${{ matrix.php != '8.3' }} - uses: "ramsey/composer-install@v2" - with: - composer-options: '--optimize-autoloader' - # Bust the cache at least once a month - output format: YYYY-MM. - custom-cache-suffix: $(date -u "+%Y-%m") - - - name: Install Composer dependencies - if: ${{ matrix.php == '8.3' }} - uses: "ramsey/composer-install@v2" - with: - composer-options: '--ignore-platform-reqs --optimize-autoloader' - custom-cache-suffix: $(date -u "+%Y-%m") - - - name: Run integration tests - run: vendor/bin/phpunit --no-coverage diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml deleted file mode 100644 index 1ee49c71..00000000 --- a/.github/workflows/linting.yaml +++ /dev/null @@ -1,53 +0,0 @@ ---- -name: Linting jobs - -on: - - push - - pull_request - - workflow_dispatch - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - validate-composer: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Validate composer.json and composer.lock - uses: "docker://composer" - with: - args: "composer validate --no-check-lock" - - lint-json: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Lint json - uses: "docker://pipelinecomponents/jsonlint:latest" - with: - args: "find . -not -path './.git/*' -name '*.json' -type f -exec jsonlint --quiet {} ;" - - yamllint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Check yaml for issues - uses: pipeline-components/yamllint@master - - php-codesniffer: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Check php for code style and php cross-version compatibility issues - uses: pipeline-components/php-codesniffer@master - - lint-remark: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Check markdown - uses: pipeline-components/remark-lint@master diff --git a/.github/workflows/phplint.yml b/.github/workflows/phplint.yml deleted file mode 100644 index 53d6c61e..00000000 --- a/.github/workflows/phplint.yml +++ /dev/null @@ -1,46 +0,0 @@ ---- -name: PHP Lint - -on: - - push - - pull_request - # Allow manually triggering the workflow. - - workflow_dispatch - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - phplint: - runs-on: ubuntu-latest - - strategy: - matrix: - php: ['5.4', '5.6', '7.2', 'latest'] - - name: "PHP Lint: PHP ${{ matrix.php }}" - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: none - tools: cs2pr - - # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies - - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" - with: - # Bust the cache at least once a month - output format: YYYY-MM. - custom-cache-suffix: $(date -u "+%Y-%m") - - - name: Lint against parse errors - run: composer lint -- --checkstyle | cs2pr diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml deleted file mode 100644 index 1422bda7..00000000 --- a/.github/workflows/quicktest.yml +++ /dev/null @@ -1,69 +0,0 @@ ---- -name: Quicktest - -on: - # Run on pushes to feature branches. - push: - branches-ignore: - - master - # Allow manually triggering the workflow. - workflow_dispatch: - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - #### QUICK TEST STAGE #### - # This is a much quicker test which only runs the integration tests against a limited set of - # supported PHP/PHPCS combinations. - quicktest: - runs-on: "${{ matrix.os }}" - - strategy: - matrix: - php: - - '5.4' - - '7.2' - - 'latest' - composer: - - 'v1' - - 'v2' - os: - - 'ubuntu-latest' - - 'windows-latest' - - name: "Quick test" - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: json, zip - ini-values: zend.assertions=1, error_reporting=-1, display_errors=On - tools: "composer:${{ matrix.composer }}" - coverage: none - env: - fail-fast: true - - - name: "Conditionally disable tls (Composer 1.x/Windows/PHP 5.4)" - if: ${{ matrix.os == 'windows-latest' && matrix.composer == 'v1' && matrix.php == '5.4' }} - run: composer config -- disable-tls true - - # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies - - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" - with: - composer-options: '--optimize-autoloader' - # Bust the cache at least once a month - output format: YYYY-MM. - custom-cache-suffix: $(date -u "+%Y-%m") - - - name: Run integration tests - run: vendor/bin/phpunit --no-coverage diff --git a/.github/workflows/securitycheck.yml b/.github/workflows/securitycheck.yml deleted file mode 100644 index 4c4e445b..00000000 --- a/.github/workflows/securitycheck.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -name: Security check - -on: - - push - - pull_request - # Allow manually triggering the workflow. - - workflow_dispatch - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - security-check: - runs-on: ubuntu-latest - name: "Security check" - - strategy: - matrix: - php: ['5.4', 'latest'] - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - coverage: none - - # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies - - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" - with: - # Bust the cache at least once a month - output format: YYYY-MM. - custom-cache-suffix: $(date -u "+%Y-%m") - - - name: Download security checker - # yamllint disable-line rule:line-length - run: wget -P . https://github.com/fabpot/local-php-security-checker/releases/download/v2.0.6/local-php-security-checker_2.0.6_linux_amd64 - - - name: Make security checker executable - run: chmod +x ./local-php-security-checker_2.0.6_linux_amd64 - - - name: Check against insecure dependencies - run: ./local-php-security-checker_2.0.6_linux_amd64 --path=composer.lock diff --git a/.github_changelog_generator b/.github_changelog_generator deleted file mode 100644 index 2c49b325..00000000 --- a/.github_changelog_generator +++ /dev/null @@ -1,34 +0,0 @@ -add-issues-wo-labels=true -add-pr-wo-labels=true -author=true -breaking-labels=backwards-incompatible,Backwards incompatible,breaking -breaking-prefix=### Breaking changes -bug-labels=bug - confirmed -bug-prefix=### Fixes -compare-link=true -date-format=%Y-%m-%d -deprecated-labels=deprecated,Deprecated,Type: Deprecated -deprecated-prefix=### Deprecates -enhancement-labels=improvement,documentation,builds / deploys / releases,feature request -enhancement-prefix=### Changes -exclude-labels=bug - unconfirmed,can't reproduce / won't fix,invalid,triage -filter-issues-by-milestone=true -header= -http-cache=true -issues=true -issue-prefix=### Closes -merge-prefix=### Pull request(s) without label -output= -project=composer-installer -pulls=true -removed-labels=removed,Removed,Type: Removed -removed-prefix=### Removes -security-labels=security,Security,Type: Security -security-prefix=### Security -summary-labels=Release summary,release-summary,Summary,summary -unreleased=true -unreleased-label=Unreleased -unreleased-only=true -user=PHPCSStandards -usernames-as-github-logins=true -verbose=false diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 568b9ede..00000000 --- a/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -vendor/ -composer.lock -.phpcs.xml -phpcs.xml -.phpunit.result.cache -phpunit.xml -/build/ -/tests/artifact/*.zip diff --git a/.remarkrc b/.remarkrc deleted file mode 100644 index bfa065da..00000000 --- a/.remarkrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": [ - "remark-preset-lint-recommended", - ["remark-lint-list-item-indent", "space"] - ] -} diff --git a/.yamllint b/.yamllint deleted file mode 100644 index ef433bd4..00000000 --- a/.yamllint +++ /dev/null @@ -1,8 +0,0 @@ ---- -extends: default - -rules: - line-length: - level: warning - max: 120 - truthy: {allowed-values: ["true", "false", "on"]} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index a408703d..00000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,129 +0,0 @@ - -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, religion, or sexual identity -and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -* Focusing on what is best not just for us as individuals, but for the - overall community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or - advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email - address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -. -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series -of actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or -permanent ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within -the community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.0, available at -https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. - -Community Impact Guidelines were inspired by [Mozilla's code of conduct -enforcement ladder](https://github.com/mozilla/diversity). - -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 5c4b8d99..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,167 +0,0 @@ -# Contributing - -When contributing to this repository, please first discuss the change you wish -to make via issue, email, or any other method with the owners of this repository -before making a change. - -Please note we have [a code of conduct][], please follow it in all your interactions -with the project. - -[a code of conduct]: https://github.com/PHPCSStandards/composer-installer/blob/master/CODE_OF_CONDUCT.md - -## Issues and feature requests - -You've found a bug in the source code, a mistake in the documentation or maybe -you'd like a new feature? You can help us by submitting an issue to our -[GitHub Repository][github]. Before you create an issue, make sure you search -the archive, maybe your question was already answered. - -Even better: You could submit a pull request with a fix / new feature! - -## Pull request process - -1. Search our repository for open or closed [pull requests][prs] that relate - to your submission. You don't want to duplicate effort. - -2. All pull requests are expected to be accompanied by tests which cover the change. - -3. You may merge the pull request in once you have the sign-off of two other - developers, or if you do not have permission to do that, you may request - the second reviewer to merge it for you. - -### (Code) Quality checks - -Every merge-request triggers a build process which runs various checks to help -maintain a quality standard. All JSON, Markdown, PHP, and Yaml files are -expected to adhere to these quality standards. - -These tools fall into two categories: PHP and non-PHP. - -### PHP - -The PHP specific tools used by this build are: - -- [PHPUnit][] and the [PHPUnit Polyfills][] for the integration tests. -- [PHP_CodeSniffer][] to verify PHP code complies with the [PSR12][] standard. -- [PHPCompatibility][] to verify that code is written in a PHP cross-version compatible manner. -- [PHP-Parallel-Lint][] to check against parse errors in PHP files. -- [PHP-Security-Checker][] to prevent insecure dependencies being installed. - -The automated checks with these tools are run via [GitHub Actions][]. - -As most of these tools are included as Composer `require-dev` packages, they can be -run locally with PHP. - -For the Parallel Lint check, the `composer lint` script has been added for convenience. - -The Security Checker package is not included in the Composer configuration. An executable -can be downloaded suitable for your operating system from their [releases page][]. - -Alternatively, these tools can be run using `docker run`, through the Docker -images provided by [Pipeline-Component][]. - -[PHPUnit]: https://phpunit.de/ -[PHPUnit Polyfills]: https://github.com/Yoast/PHPUnit-Polyfills/ -[PHP_CodeSniffer]: https://github.com/squizlabs/PHP_CodeSniffer -[PHPCompatibility]: https://github.com/PHPCompatibility/PHPCompatibility -[PHP-Parallel-Lint]: https://github.com/php-parallel-lint/PHP-Parallel-Lint -[PHP-Security-Checker]: https://github.com/fabpot/local-php-security-checker -[PSR12]: https://www.php-fig.org/psr/psr-12/ -[releases page]: https://github.com/fabpot/local-php-security-checker/releases/ - -#### Automated testing - -This package includes a test setup for automated testing on all supported PHP versions -using [PHPUnit][] with the [PHPUnit Polyfills][]. -This means that tests can be written for the latest version of PHPUnit -(9.x at the time of writing) and still be run on all PHPUnit versions needed to test -all supported PHP versions (PHPUnit 4.x - 9.x). - -The tests can be run both via a Composer installed version of PHPUnit, as well as using -a PHPUnit PHAR file, however, whichever way you run the tests, you will always need to -make sure that `composer install` has been run on the repository to make sure the -PHPUnit Polyfills are available. - -**Note**: _as these tests run Composer and other CLI commands they will be slow to run._ - -To run the tests locally: -1. Run `composer install` -2. Run the tests either using a PHPUnit PHAR file or by calling `composer test`. - -In case the test setup has trouble locating your `composer.phar` file: - -1. Copy the `phpunit.xml.dist` file to `phpunit.xml`. - -2. Edit the `phpunit.xml` file and add the following, replacing the value with the applicable path to Composer for your local machine: - ```xml - - - - ``` - **Note**: this setting also allows for locally testing with different versions of Composer. - You could, for instance, have multiple Composer Phar files locally, `composer1.phar`, `composer2.1.phar`, `composer2.2.phar`. - By changing the path in the value of this `env` setting, you can switch which version will be used in the tests. - -### Non-PHP - -The non-PHP specific tools used by this build are: - -- [jsonlint][] to verify that all JSON files use a consistent code style. -- [remark-lint][] to verify that all markdown files use a consistent code style. -- [yamllint][] to verify that all Yaml files use a consistent code style. - -These tools are also run as [GitHub actions][]. -All the checks can be run locally using [`act`][]. -Alternatively they can be run using `docker run`, as all checks use Docker -images provided by [Pipeline-Component][]. - -Finally, they could be run locally using NodeJS, Ruby, PHP, or whatever the tool -is written in. For details please consult the relevant tool's documentation. - -[jsonlint]: https://www.npmjs.com/package/jsonlint -[remark-lint]: https://www.npmjs.com/package/remark-lint -[yamllint]: https://yamllint.readthedocs.io/en/stable/ -[`act`]: https://github.com/nektos/act - -## Release process - -To make it possible to automatically generate a changelog, all tickets/issues must have a milestone and at least one label. - -A changelog can be generated using the [`github-changelog-generator`][github-changelog-generator].[(1)](#footnotes) - -Our release versions follow [Semantic Versioning][semver]. - -New releases (and any related tags) are always created from the `master` branch. - -To create a new release: - -1. Make sure all closed tickets and MRs have a label. - -2. Make sure all closed tickets and MRs are added to the milestone that is to be released. - -3. Move any open tickets to the next milestone (create a new one if needed). - -4. Generate a changelog by running `github_changelog_generator` in the project root:[(2)](#footnotes) - ``` - github_changelog_generator --future-release "${sVersion}" --header --output --unreleased-only 2>/dev/null - ``` - Where `sVersion` contains the new version to release. - -5. Use GitHub "Draft a new release" functionality to draft a new release (this also creates a tag). - -6. Close the milestone for the version that was just released. - -[github]: https://github.com/PHPCSStandards/composer-installer/issues -[prs]: https://github.com/PHPCSStandards/composer-installer/pulls -[GitHub Actions]: https://github.com/PHPCSStandards/composer-installer/actions -[Pipeline-Component]: https://pipeline-components.dev/ - -## Footnotes - -1. All settings needed for the changelog-generator are set in `.github_changelog_generator` file. - -2. A convenience script is present at `bin/generate-changelog.sh` that will install the changelog-generator, if it is not present, and run the appropriate `github_changelog_generator` command. - The script requires BASH to run. It should be run from the project root, similar to `github_changelog_generator`. - -[github-changelog-generator]: https://github.com/github-changelog-generator/github-changelog-generator/ -[semver]: https://semver.org/ diff --git a/README.md b/README.md index e8c263ab..83685f21 100644 --- a/README.md +++ b/README.md @@ -1,285 +1,9 @@ # PHP_CodeSniffer Standards Composer Installer Plugin -![Project Stage][project-stage-shield] -![Last Commit][last-updated-shield] -![Awesome][awesome-shield] -[![License][license-shield]](LICENSE.md) +This project has been renamed to `phpcsstandards/composer-installer`. -[![Tests][ghactionstest-shield]][ghactions] -[![Latest Version on Packagist][packagist-version-shield]][packagist-version] -[![Packagist][packagist-shield]][packagist] +Please use that instead: -[![Contributor Covenant][code-of-conduct-shield]][code-of-conduct] - -This composer installer plugin allows for easy installation of [PHP_CodeSniffer][codesniffer] coding standards (rulesets). - -No more symbolic linking of directories, checking out repositories on specific locations or changing -the `phpcs` configuration. - -## Usage - -Installation can be done with [Composer][composer], by requiring this package as a development dependency: - -```bash -composer require --dev dealerdirect/phpcodesniffer-composer-installer -``` - -When using Composer 2.2 or higher, Composer will [ask for your permission](https://blog.packagist.com/composer-2-2/#more-secure-plugin-execution) to allow this plugin to execute code. For this plugin to be functional, permission needs to be granted. - -When permission has been granted, the following snippet will automatically be added to your `composer.json` file by Composer: -```json -{ - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} -``` - -When using Composer < 2.2, you can add the permission flag ahead of the upgrade to Composer 2.2, by running: -```bash -composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true -``` - -That's it. - -### Compatibility - -This plugin is compatible with: - -- PHP **5.4+**, **7.x**, and **8.x** (Support for PHP v8 is available since [`v0.7.0`][v0.7]) -- [Composer][composer] **1.x** and **2.x** (Support for Composer v2 is available since [`v0.7.0`][v0.7]) -- [PHP_CodeSniffer][codesniffer] **2.x** and **3.x** (Support for PHP_CodeSniffer v3 is available since [`v0.4.0`][v0.4]) - - -> **ℹ️ Please Note:** [Composer treats _minor_ releases below 1.0.0 as _major_ releases][composer-manual-caret]. So version `0.7.x` (or higher) of this plugin must be _explicitly_ set as version constraint when using Composer 2.x or PHP 8.0. In other words: using `^0.6` will **not** work with Composer 2.x or PHP 8.0. - -### How it works - -Basically, this plugin executes the following steps: - -- This plugin searches for [`phpcodesniffer-standard` packages][] in all of your currently installed Composer packages. -- Matching packages and the project itself are scanned for PHP_CodeSniffer rulesets. -- The plugin will call PHP_CodeSniffer and configure the `installed_paths` option. - -### Example project - -The following is an example Composer project and has included -multiple `phpcodesniffer-standard` packages. - -```json -{ - "name": "example/project", - "description": "Just an example project", - "type": "project", - "require": {}, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "*", - "object-calisthenics/phpcs-calisthenics-rules": "*", - "phpcompatibility/php-compatibility": "*", - "wp-coding-standards/wpcs": "*" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} -``` - -After running `composer install` PHP_CodeSniffer just works: - -```bash -$ ./vendor/bin/phpcs -i -The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, ObjectCalisthenics, -PHPCompatibility, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra -``` - -### Calling the plugin directly - -In some circumstances, it is desirable to call this plugin's functionality -directly. For instance, during development or in [CI][definition-ci] environments. - -As the plugin requires Composer to work, direct calls need to be wired through a -project's `composer.json`. - -This is done by adding a call to the `Plugin::run` function in the `script` -section of the `composer.json`: - -```json -{ - "scripts": { - "install-codestandards": [ - "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" - ] - } -} -``` - -The command can then be called using `composer run-script install-codestandards` or -referenced from other script configurations, as follows: - -```json -{ - "scripts": { - "install-codestandards": [ - "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" - ], - "post-install-cmd": [ - "@install-codestandards" - ] - } -} +```sh +composer require `phpcsstandards/composer-installer` ``` - -For more details about Composer scripts, please refer to [the section on scripts -in the Composer manual][composer-manual-scripts]. - -### Changing the Coding Standards search depth - -By default, this plugin searches up for Coding Standards up to three directories -deep. In most cases, this should be sufficient. However, this plugin allows -you to customize the search depth setting if needed. - -```json -{ - "extra": { - "phpcodesniffer-search-depth": 5 - } -} -``` - -### Caveats - -When this plugin is installed globally, composer will load the _global_ plugin rather -than the one from the local repository. Despite [this behavior being documented -in the composer manual][using-composer-plugins], it could potentially confuse -as another version of the plugin could be run and not the one specified by the project. - -## Developing Coding Standards - -Coding standard can be developed normally, as documented by [PHP_CodeSniffer][codesniffer], in the [Coding Standard Tutorial][tutorial]. - -Create a composer package of your coding standard by adding a `composer.json` file. - -```json -{ - "name" : "acme/phpcodesniffer-our-standards", - "description" : "Package contains all coding standards of the Acme company", - "require" : { - "php" : ">=5.4.0", - "squizlabs/php_codesniffer" : "^3.6" - }, - "type" : "phpcodesniffer-standard" -} -``` - -Requirements: -* The repository may contain one or more standards. -* Each standard can have a separate directory no deeper than 3 levels from the repository root. -* The package `type` must be `phpcodesniffer-standard`. Without this, the plugin will not trigger. - -### Requiring the plugin from within your coding standard - -If your coding standard itself depends on additional external PHPCS standards, this plugin can -make life easier on your end-users by taking care of the installation of all standards - yours -and your dependencies - for them. - -This can help reduce the number of support questions about setting the `installed_paths`, as well -as simplify your standard's installation instructions. - -For this to work, make sure your external standard adds this plugin to the `composer.json` config -via `require`, **not** `require-dev`. - -> :warning: Your end-user may already `require-dev` this plugin and/or other external standards used -> by your end-users may require this plugin as well. -> -> To prevent your end-users getting into "_dependency hell_", make sure to make the version requirement -> for this plugin flexible. -> -> As, for now, this plugin is still regarded as "unstable" (version < 1.0), remember that Composer -> treats unstable minors as majors and will not be able to resolve one config requiring this plugin -> at version `^0.5`, while another requires it at version `^0.6`. -> Either allow multiple minors or use `*` as the version requirement. -> -> Some examples of flexible requirements which can be used: -> ```bash -> composer require dealerdirect/phpcodesniffer-composer-installer:"*" -> composer require dealerdirect/phpcodesniffer-composer-installer:"0.*" -> composer require dealerdirect/phpcodesniffer-composer-installer:"^0.4.1 || ^0.5 || ^0.6 || ^0.7" -> ``` - -## Changelog - -This repository does not contain a `CHANGELOG.md` file, however, we do publish a changelog on each release -using the [GitHub releases][changelog] functionality. - -## Contributing - -This is an active open-source project. We are always open to people who want to -use the code or contribute to it. - -We've set up a separate document for our [contribution guidelines][contributing-guidelines]. - -Thank you for being involved! :heart_eyes: - -## Authors & contributors - -The original idea and setup of this repository is by [Franck Nijhof][frenck], employee @ Dealerdirect. - -For a full list of all author and/or contributors, check [the contributors page][contributors]. - -## License - -The MIT License (MIT) - -Copyright (c) 2016-2022 Dealerdirect B.V. and contributors -Copyright (c) 2022 PHPCSStandards and contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -[awesome-shield]: https://img.shields.io/badge/awesome%3F-yes-brightgreen.svg -[changelog]: https://github.com/PHPCSStandards/composer-installer/releases -[code-of-conduct-shield]: https://img.shields.io/badge/Contributor%20Covenant-v2.0-ff69b4.svg -[code-of-conduct]: CODE_OF_CONDUCT.md -[codesniffer]: https://github.com/squizlabs/PHP_CodeSniffer -[composer-manual-scripts]: https://getcomposer.org/doc/articles/scripts.md -[composer-manual-caret]: https://getcomposer.org/doc/articles/versions.md#caret-version-range- -[composer]: https://getcomposer.org/ -[contributing-guidelines]: CONTRIBUTING.md -[contributors]: https://github.com/PHPCSStandards/composer-installer/graphs/contributors -[definition-ci]: https://en.wikipedia.org/wiki/Continuous_integration -[frenck]: https://github.com/frenck -[last-updated-shield]: https://img.shields.io/github/last-commit/PHPCSStandards/composer-installer.svg -[license-shield]: https://img.shields.io/github/license/PHPCSStandards/composer-installer.svg -[packagist-shield]: https://img.shields.io/packagist/dt/dealerdirect/phpcodesniffer-composer-installer.svg -[packagist-version-shield]: https://img.shields.io/packagist/v/dealerdirect/phpcodesniffer-composer-installer.svg -[packagist-version]: https://packagist.org/packages/dealerdirect/phpcodesniffer-composer-installer -[packagist]: https://packagist.org/packages/dealerdirect/phpcodesniffer-composer-installer -[`phpcodesniffer-standard` packages]: https://packagist.org/explore/?type=phpcodesniffer-standard -[project-stage-shield]: https://img.shields.io/badge/Project%20Stage-Development-yellowgreen.svg -[scrutinizer-shield]: https://img.shields.io/scrutinizer/g/dealerdirect/phpcodesniffer-composer-installer.svg -[scrutinizer]: https://scrutinizer-ci.com/g/dealerdirect/phpcodesniffer-composer-installer/ -[ghactionstest-shield]: https://github.com/PHPCSStandards/composer-installer/actions/workflows/integrationtest.yml/badge.svg -[ghactions]: https://github.com/PHPCSStandards/composer-installer/actions/workflows/integrationtest.yml -[tutorial]: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial -[using-composer-plugins]: https://getcomposer.org/doc/articles/plugins.md#using-plugins -[v0.4]: https://github.com/PHPCSStandards/composer-installer/releases/tag/v0.4.0 -[v0.7]: https://github.com/PHPCSStandards/composer-installer/releases/tag/v0.7.0 diff --git a/bin/generate-changelog.sh b/bin/generate-changelog.sh deleted file mode 100644 index 25aa0009..00000000 --- a/bin/generate-changelog.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o errtrace -o nounset -o pipefail - -: ${GITHUB_CHANGELOG_GENERATOR:=github_changelog_generator} -: ${GEM:=gem} - -generate_changelog() { - local -r sVersion="${1?One parameter required: }" - - if ! command -v "${GITHUB_CHANGELOG_GENERATOR}" >/dev/null 2>&1;then - echo "This script requires the '${GITHUB_CHANGELOG_GENERATOR}' Ruby Gem" - - if ! command -v "${GEM}" >/dev/null 2>&1;then - echo "Could not find the '${GEM}' command needed to install 'github_changelog_generator'!" >&2 - echo 'Aborting.' - exit 67 - else - echo "Installing '${GITHUB_CHANGELOG_GENERATOR}'..." - gem install github_changelog_generator - fi - fi - - local -r sChangelog="$( - "${GITHUB_CHANGELOG_GENERATOR}" \ - --user PHPCSStandards \ - --project composer-installer \ - --token "$(cat ~/.github-token)" \ - --future-release "${sVersion}" \ - --enhancement-label '### Changes' \ - --bugs-label '### Fixes' \ - --issues-label '### Closes' \ - --usernames-as-github-logins \ - --bug-labels 'bug - confirmed' \ - --enhancement-labels 'improvement','documentation','builds / deploys / releases','feature request' \ - --exclude-labels 'bug - unconfirmed',"can't reproduce / won't fix",'invalid','triage' \ - --unreleased-only \ - --output '' 2>/dev/null - )" || echo "There was a problem running '${GITHUB_CHANGELOG_GENERATOR}'" - - echo "${sChangelog}" | sed -E 's/\[\\(#[0-9]+)\]\([^)]+\)/\1/' | head -n -3 -} - -if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then - export -f generate_changelog -else - generate_changelog "${@}" - exit $? -fi diff --git a/composer.json b/composer.json index bf3355ac..aeb2c267 100644 --- a/composer.json +++ b/composer.json @@ -1,71 +1,31 @@ { "name": "dealerdirect/phpcodesniffer-composer-installer", - "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "description": "⚠️ Please migrate to phpcsstandards/composer-installer ⚠️", "type": "composer-plugin", - "keywords": [ - "composer", "installer", "plugin", - "phpcs", "phpcbf", "codesniffer", "phpcodesniffer", "php_codesniffer", - "standard", "standards", "style guide", "stylecheck", - "qa", "quality", "code quality", "tests" - ], - "homepage": "http://www.dealerdirect.com", + "abandoned": true, + "suggest": { + "phpcsstandards/composer-installer": "The renamed version of this package" + }, + "homepage": "https://github.com/PHPCSStandards/composer-installer", "license": "MIT", - "authors": [ - { - "name": "Franck Nijhof", - "email": "franck.nijhof@dealerdirect.com", - "homepage": "http://www.frenck.nl", - "role": "Developer / IT Manager" - }, - { - "name" : "Contributors", - "homepage" : "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" - } - ], "support": { "issues": "https://github.com/PHPCSStandards/composer-installer/issues", "source": "https://github.com/PHPCSStandards/composer-installer" }, "require": { - "php": ">=5.4", - "composer-plugin-api": "^1.0 || ^2.0", - "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" - }, - "require-dev": { - "ext-json": "*", - "ext-zip": "*", - "composer/composer": "*", - "phpcompatibility/php-compatibility": "^9.0", - "php-parallel-lint/php-parallel-lint": "^1.3.1", - "yoast/phpunit-polyfills": "^1.0" + "phpcsstandards/composer-installer": "*" }, - "minimum-stability": "dev", - "prefer-stable": true, "autoload": { "psr-4": { - "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Tests\\": "tests/" + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" } }, "extra": { - "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" }, "scripts": { "install-codestandards": [ - "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" - ], - "lint": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" - ], - "test": [ - "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" - ], - "coverage": [ - "@php ./vendor/phpunit/phpunit/phpunit" + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" ] } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 493a03ea..00000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,40 +0,0 @@ - - - Coding standards for PHP_CodeSniffer Standards Composer Installer Plugin - - - - - - - - . - */.git* - */build/* - */vendor/* - - - - - - - - - - - - - - - - - */tests/bootstrap\.php$ - - - - - */tests/ - - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index d71e5069..00000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - tests/IntegrationTest/ - - - - - - - - - - ./src/ - - - - - - - - diff --git a/src/Plugin.php b/src/Plugin.php index a2863d6c..7275a047 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -10,628 +10,11 @@ namespace PHPCSStandards\Composer\Plugin\Installers\PHPCodeSniffer; -use Composer\Composer; -use Composer\EventDispatcher\EventSubscriberInterface; -use Composer\IO\IOInterface; -use Composer\Package\AliasPackage; -use Composer\Package\PackageInterface; -use Composer\Package\RootPackageInterface; -use Composer\Plugin\PluginInterface; -use Composer\Script\Event; -use Composer\Script\ScriptEvents; -use Composer\Util\Filesystem; -use Composer\Util\ProcessExecutor; -use Symfony\Component\Finder\Finder; -use Symfony\Component\Process\Exception\LogicException; -use Symfony\Component\Process\Exception\ProcessFailedException; -use Symfony\Component\Process\Exception\RuntimeException; -use Symfony\Component\Process\PhpExecutableFinder; - /** - * PHP_CodeSniffer standard installation manager. + * This class is a pure proxy for the renamed package phpcsstandards/composer-installer + * + * @see https://github.com/PHPCSStandards/composer-installer/issues/159 * - * @author Franck Nijhof + * @deprecated Please use PHPCSStandards/composer-installer instead */ -class Plugin implements PluginInterface, EventSubscriberInterface -{ - const KEY_MAX_DEPTH = 'phpcodesniffer-search-depth'; - - const MESSAGE_ERROR_WRONG_MAX_DEPTH = - 'The value of "%s" (in the composer.json "extra".section) must be an integer larger than %d, %s given.'; - - const MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed'; - const MESSAGE_NOTHING_TO_INSTALL = 'No PHPCS standards to install or update'; - const MESSAGE_PLUGIN_UNINSTALLED = 'PHPCodeSniffer Composer Installer is uninstalled'; - const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'; - - const PACKAGE_NAME = 'squizlabs/php_codesniffer'; - const PACKAGE_TYPE = 'phpcodesniffer-standard'; - - const PHPCS_CONFIG_REGEX = '`%s:[^\r\n]+`'; - const PHPCS_CONFIG_KEY = 'installed_paths'; - - const PLUGIN_NAME = 'dealerdirect/phpcodesniffer-composer-installer'; - - /** - * @var Composer - */ - private $composer; - - /** - * @var string - */ - private $cwd; - - /** - * @var Filesystem - */ - private $filesystem; - - /** - * @var array - */ - private $installedPaths; - - /** - * @var IOInterface - */ - private $io; - - /** - * @var ProcessExecutor - */ - private $processExecutor; - - /** - * Triggers the plugin's main functionality. - * - * Makes it possible to run the plugin as a custom command. - * - * @param Event $event - * - * @throws \InvalidArgumentException - * @throws \RuntimeException - * @throws LogicException - * @throws ProcessFailedException - * @throws RuntimeException - */ - public static function run(Event $event) - { - $io = $event->getIO(); - $composer = $event->getComposer(); - - $instance = new static(); - - $instance->io = $io; - $instance->composer = $composer; - $instance->init(); - $instance->onDependenciesChangedEvent(); - } - - /** - * {@inheritDoc} - * - * @throws \RuntimeException - * @throws LogicException - * @throws ProcessFailedException - * @throws RuntimeException - */ - public function activate(Composer $composer, IOInterface $io) - { - $this->composer = $composer; - $this->io = $io; - - $this->init(); - } - - /** - * {@inheritDoc} - */ - public function deactivate(Composer $composer, IOInterface $io) - { - } - - /** - * {@inheritDoc} - */ - public function uninstall(Composer $composer, IOInterface $io) - { - } - - /** - * Prepares the plugin so it's main functionality can be run. - * - * @throws \RuntimeException - * @throws LogicException - * @throws ProcessFailedException - * @throws RuntimeException - */ - private function init() - { - $this->cwd = getcwd(); - $this->installedPaths = array(); - - $this->processExecutor = new ProcessExecutor($this->io); - $this->filesystem = new Filesystem($this->processExecutor); - } - - /** - * {@inheritDoc} - */ - public static function getSubscribedEvents() - { - return array( - ScriptEvents::POST_INSTALL_CMD => array( - array('onDependenciesChangedEvent', 0), - ), - ScriptEvents::POST_UPDATE_CMD => array( - array('onDependenciesChangedEvent', 0), - ), - ); - } - - /** - * Entry point for post install and post update events. - * - * @throws \InvalidArgumentException - * @throws LogicException - * @throws ProcessFailedException - * @throws RuntimeException - */ - public function onDependenciesChangedEvent() - { - $io = $this->io; - $isVerbose = $io->isVerbose(); - $exitCode = 0; - - if ($isVerbose) { - $io->write(sprintf('%s', self::MESSAGE_RUNNING_INSTALLER)); - } - - if ($this->isPHPCodeSnifferInstalled() === true) { - $this->loadInstalledPaths(); - $installPathCleaned = $this->cleanInstalledPaths(); - $installPathUpdated = $this->updateInstalledPaths(); - - if ($installPathCleaned === true || $installPathUpdated === true) { - $exitCode = $this->saveInstalledPaths(); - } elseif ($isVerbose) { - $io->write(sprintf('%s', self::MESSAGE_NOTHING_TO_INSTALL)); - } - } else { - $pluginPackage = $this - ->composer - ->getRepositoryManager() - ->getLocalRepository() - ->findPackages(self::PLUGIN_NAME) - ; - - $isPluginUninstalled = count($pluginPackage) === 0; - - if ($isPluginUninstalled) { - if ($isVerbose) { - $io->write(sprintf('%s', self::MESSAGE_PLUGIN_UNINSTALLED)); - } - } else { - $exitCode = 1; - if ($isVerbose) { - $io->write(sprintf('%s', self::MESSAGE_NOT_INSTALLED)); - } - } - } - - return $exitCode; - } - - /** - * Load all paths from PHP_CodeSniffer into an array. - * - * @throws LogicException - * @throws ProcessFailedException - * @throws RuntimeException - */ - private function loadInstalledPaths() - { - if ($this->isPHPCodeSnifferInstalled() === true) { - $this->processExecutor->execute( - $this->getPhpcsCommand() . ' --config-show', - $output, - $this->getPHPCodeSnifferInstallPath() - ); - - $regex = sprintf(self::PHPCS_CONFIG_REGEX, self::PHPCS_CONFIG_KEY); - if (preg_match($regex, $output, $match) === 1) { - $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $match[0]); - $phpcsInstalledPaths = trim($phpcsInstalledPaths); - - if ($phpcsInstalledPaths !== '') { - $this->installedPaths = explode(',', $phpcsInstalledPaths); - } - } - } - } - - /** - * Save all coding standard paths back into PHP_CodeSniffer - * - * @throws LogicException - * @throws ProcessFailedException - * @throws RuntimeException - * - * @return int Exit code. 0 for success, 1 or higher for failure. - */ - private function saveInstalledPaths() - { - // Check if we found installed paths to set. - if (count($this->installedPaths) !== 0) { - sort($this->installedPaths); - $paths = implode(',', $this->installedPaths); - $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths); - $configMessage = sprintf( - 'PHP CodeSniffer Config %s set to %s', - self::PHPCS_CONFIG_KEY, - $paths - ); - } else { - // Delete the installed paths if none were found. - $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY); - $configMessage = sprintf( - 'PHP CodeSniffer Config %s delete', - self::PHPCS_CONFIG_KEY - ); - } - - // Prepare message in case of failure - $failMessage = sprintf( - 'Failed to set PHP CodeSniffer %s Config', - self::PHPCS_CONFIG_KEY - ); - - // Okay, lets rock! - $command = vsprintf( - '%s %s', - array( - 'phpcs command' => $this->getPhpcsCommand(), - 'arguments' => implode(' ', $arguments), - ) - ); - - $exitCode = $this->processExecutor->execute($command, $configResult, $this->getPHPCodeSnifferInstallPath()); - if ($exitCode === 0) { - $exitCode = $this->verifySaveSuccess(); - } - - if ($exitCode === 0) { - $this->io->write($configMessage); - } else { - $this->io->write($failMessage); - } - - if ($this->io->isVerbose() && !empty($configResult)) { - $this->io->write(sprintf('%s', $configResult)); - } - - return $exitCode; - } - - /** - * Verify that the paths which were expected to be saved, have been. - * - * @return int Exit code. 0 for success, 1 for failure. - */ - private function verifySaveSuccess() - { - $exitCode = 1; - $expectedPaths = $this->installedPaths; - - // Request the currently set installed paths after the save. - $this->loadInstalledPaths(); - - $registeredPaths = array_intersect($this->installedPaths, $expectedPaths); - $registeredCount = count($registeredPaths); - $expectedCount = count($expectedPaths); - - if ($expectedCount === $registeredCount) { - $exitCode = 0; - } - - if ($exitCode === 1 && $this->io->isVerbose()) { - $verificationMessage = sprintf( - "Paths to external standards found by the plugin: %s\n" - . 'Actual paths registered with PHPCS: %s', - implode(', ', $expectedPaths), - implode(', ', $this->installedPaths) - ); - $this->io->write($verificationMessage); - } - - return $exitCode; - } - - /** - * Get the command to call PHPCS. - */ - protected function getPhpcsCommand() - { - // Determine the path to the main PHPCS file. - $phpcsPath = $this->getPHPCodeSnifferInstallPath(); - if (file_exists($phpcsPath . '/bin/phpcs') === true) { - // PHPCS 3.x. - $phpcsExecutable = './bin/phpcs'; - } else { - // PHPCS 2.x. - $phpcsExecutable = './scripts/phpcs'; - } - - return vsprintf( - '%s %s', - array( - 'php executable' => $this->getPhpExecCommand(), - 'phpcs executable' => $phpcsExecutable, - ) - ); - } - - /** - * Get the path to the current PHP version being used. - * - * Duplicate of the same in the EventDispatcher class in Composer itself. - */ - protected function getPhpExecCommand() - { - $finder = new PhpExecutableFinder(); - - $phpPath = $finder->find(false); - - if ($phpPath === false) { - throw new \RuntimeException('Failed to locate PHP binary to execute ' . $phpPath); - } - - $phpArgs = $finder->findArguments(); - $phpArgs = $phpArgs - ? ' ' . implode(' ', $phpArgs) - : '' - ; - - $command = ProcessExecutor::escape($phpPath) . - $phpArgs . - ' -d allow_url_fopen=' . ProcessExecutor::escape(ini_get('allow_url_fopen')) . - ' -d disable_functions=' . ProcessExecutor::escape(ini_get('disable_functions')) . - ' -d memory_limit=' . ProcessExecutor::escape(ini_get('memory_limit')) - ; - - return $command; - } - - /** - * Iterate trough all known paths and check if they are still valid. - * - * If path does not exists, is not an directory or isn't readable, the path - * is removed from the list. - * - * @return bool True if changes where made, false otherwise - */ - private function cleanInstalledPaths() - { - $changes = false; - foreach ($this->installedPaths as $key => $path) { - // This might be a relative path as well - $alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . \DIRECTORY_SEPARATOR . $path); - - if ( - (is_dir($path) === false || is_readable($path) === false) && - ( - $alternativePath === false || - is_dir($alternativePath) === false || - is_readable($alternativePath) === false - ) - ) { - unset($this->installedPaths[$key]); - $changes = true; - } - } - return $changes; - } - - /** - * Check all installed packages (including the root package) against - * the installed paths from PHP_CodeSniffer and add the missing ones. - * - * @return bool True if changes where made, false otherwise - * - * @throws \InvalidArgumentException - * @throws \RuntimeException - */ - private function updateInstalledPaths() - { - $changes = false; - $searchPaths = array(); - - // Add root package only if it has the expected package type. - if ( - $this->composer->getPackage() instanceof RootPackageInterface - && $this->composer->getPackage()->getType() === self::PACKAGE_TYPE - ) { - $searchPaths[] = $this->cwd; - } - - $codingStandardPackages = $this->getPHPCodingStandardPackages(); - foreach ($codingStandardPackages as $package) { - $installPath = $this->composer->getInstallationManager()->getInstallPath($package); - if ($this->filesystem->isAbsolutePath($installPath) === false) { - $installPath = $this->filesystem->normalizePath( - $this->cwd . \DIRECTORY_SEPARATOR . $installPath - ); - } - $searchPaths[] = $installPath; - } - - // Nothing to do. - if ($searchPaths === array()) { - return false; - } - - $finder = new Finder(); - $finder->files() - ->depth('<= ' . $this->getMaxDepth()) - ->depth('>= ' . $this->getMinDepth()) - ->ignoreUnreadableDirs() - ->ignoreVCS(true) - ->in($searchPaths) - ->name('ruleset.xml'); - - // Process each found possible ruleset. - foreach ($finder as $ruleset) { - $standardsPath = $ruleset->getPath(); - - // Pick the directory above the directory containing the standard, unless this is the project root. - if ($standardsPath !== $this->cwd) { - $standardsPath = dirname($standardsPath); - } - - // Use relative paths for local project repositories. - if ($this->isRunningGlobally() === false) { - $standardsPath = $this->filesystem->findShortestPath( - $this->getPHPCodeSnifferInstallPath(), - $standardsPath, - true - ); - } - - // De-duplicate and add when directory is not configured. - if (in_array($standardsPath, $this->installedPaths, true) === false) { - $this->installedPaths[] = $standardsPath; - $changes = true; - } - } - - return $changes; - } - - /** - * Iterates through Composers' local repository looking for valid Coding - * Standard packages. - * - * @return array Composer packages containing coding standard(s) - */ - private function getPHPCodingStandardPackages() - { - $codingStandardPackages = array_filter( - $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), - function (PackageInterface $package) { - if ($package instanceof AliasPackage) { - return false; - } - return $package->getType() === Plugin::PACKAGE_TYPE; - } - ); - - return $codingStandardPackages; - } - - /** - * Searches for the installed PHP_CodeSniffer Composer package - * - * @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against - * - * @return PackageInterface|null - */ - private function getPHPCodeSnifferPackage($versionConstraint = null) - { - $packages = $this - ->composer - ->getRepositoryManager() - ->getLocalRepository() - ->findPackages(self::PACKAGE_NAME, $versionConstraint); - - return array_shift($packages); - } - - /** - * Returns the path to the PHP_CodeSniffer package installation location - * - * @return string - */ - private function getPHPCodeSnifferInstallPath() - { - return $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage()); - } - - /** - * Simple check if PHP_CodeSniffer is installed. - * - * @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against - * - * @return bool Whether PHP_CodeSniffer is installed - */ - private function isPHPCodeSnifferInstalled($versionConstraint = null) - { - return ($this->getPHPCodeSnifferPackage($versionConstraint) !== null); - } - - /** - * Test if composer is running "global" - * This check kinda dirty, but it is the "Composer Way" - * - * @return bool Whether Composer is running "globally" - * - * @throws \RuntimeException - */ - private function isRunningGlobally() - { - return ($this->composer->getConfig()->get('home') === $this->cwd); - } - - /** - * Determines the maximum search depth when searching for Coding Standards. - * - * @return int - * - * @throws \InvalidArgumentException - */ - private function getMaxDepth() - { - $maxDepth = 3; - - $extra = $this->composer->getPackage()->getExtra(); - - if (array_key_exists(self::KEY_MAX_DEPTH, $extra)) { - $maxDepth = $extra[self::KEY_MAX_DEPTH]; - $minDepth = $this->getMinDepth(); - - if ( - (string) (int) $maxDepth !== (string) $maxDepth /* Must be an integer or cleanly castable to one */ - || $maxDepth <= $minDepth /* Larger than the minimum */ - || is_float($maxDepth) === true /* Within the boundaries of integer */ - ) { - $message = vsprintf( - self::MESSAGE_ERROR_WRONG_MAX_DEPTH, - array( - 'key' => self::KEY_MAX_DEPTH, - 'min' => $minDepth, - 'given' => var_export($maxDepth, true), - ) - ); - - throw new \InvalidArgumentException($message); - } - } - - return (int) $maxDepth; - } - - /** - * Returns the minimal search depth for Coding Standard packages. - * - * Usually this is 0, unless PHP_CodeSniffer >= 3 is used. - * - * @return int - */ - private function getMinDepth() - { - if ($this->isPHPCodeSnifferInstalled('>= 3.0.0') !== true) { - return 1; - } - return 0; - } -} +class Plugin extends \PHPCSStandards\Composer\Plugin\Installers\PHPCodeSniffer\Plugin {} diff --git a/tests/CreateComposerZipArtifacts.php b/tests/CreateComposerZipArtifacts.php deleted file mode 100644 index 33873783..00000000 --- a/tests/CreateComposerZipArtifacts.php +++ /dev/null @@ -1,249 +0,0 @@ - 'composer.lock', - 'phpcs.xml.dist' => 'phpcs.xml.dist', - 'phpunit.xml.dist' => 'phpunit.xml.dist', - 'phpunit.xml' => 'phpunit.xml', - ); - - /** - * List of file extensions for files which should be excluded from the zip archives. - * - * @var array - */ - private $excludedExtensions = array( - 'md' => 'md', - 'bak' => 'bak', - 'orig' => 'orig', - ); - - /** - * List of top-level directories which should be excluded from the zip archives. - * - * Note: no need to list directories starting with a `.` as those will always be filtered out. - * - * @var array - */ - private $excludedDirs = array( - 'bin' => 'bin', - 'build' => 'build', // PHPUnit code coverage directory. - 'tests' => 'tests', - 'vendor' => 'vendor', - ); - - /** - * Constructor. - * - * @param string $artifactDir Full path to the directory to place the sipped artifacts in. - */ - public function __construct($artifactDir) - { - // Make sure the directory has a trailing slash. - $this->artifactDir = rtrim($artifactDir, '/') . '/'; - } - - /** - * Delete all zip artifacts from the artifacts directory. - * - * @return void - */ - public function clearOldArtifacts() - { - $di = new DirectoryIterator($this->artifactDir); - foreach ($di as $fileinfo) { - if ($fileinfo->isFile() && $fileinfo->getExtension() === 'zip') { - @unlink($fileinfo->getPathname()); - } - } - } - - /** - * Create a zip file of the *current* state of the plugin to be passed to Composer as an artifact. - * - * @param string $source Path to the directory to package up. - * @param string $version Version number to use for the package. - * - * @return void - */ - public function createPluginArtifact($source, $version) - { - $fileName = "dealerdirect-phpcodesniffer-composer-installer-{$version}.zip"; - $this->createZipArtifact($source, \ZIP_ARTIFACT_DIR . $fileName, $version); - } - - /** - * Create a zip package artifact for each test fixture. - * - * @param string $source The source directory where the fixtures can be found. - * Each subdirectory of this directory will be treated as a - * package to be zipped up. - * - * @return void - */ - public function createFixtureArtifacts($source) - { - $di = new DirectoryIterator($source); - foreach ($di as $fileinfo) { - if ($fileinfo->isDot() || $fileinfo->isDir() === false) { - continue; - } - - $sourcePath = $fileinfo->getRealPath(); - $composerFile = $sourcePath . '/composer.json'; - if (file_exists($composerFile) === false) { - throw new RuntimeException( - sprintf( - 'Each fixture MUST contain a composer.json file. File not found in %s', - $composerFile - ) - ); - } - - $config = json_decode(file_get_contents($composerFile), true); - if (isset($config['name']) === false) { - throw new RuntimeException( - sprintf('The fixture composer.json file is missing the "name" for the package in %s', $composerFile) - ); - } - - $targetVersion = self::FIXTURE_VERSION; - if (isset($config['version'])) { - $targetVersion = $config['version']; - } - - $package = $config['name']; - $targetFile = str_replace('/', '-', $package) . "-{$targetVersion}.zip"; - $targetPath = $this->artifactDir . $targetFile; - - $this->createZipArtifact($sourcePath, $targetPath, $targetVersion); - } - } - - /** - * Create a zip file of an arbitrary directory and package it for use by Composer. - * - * Inspired by https://github.com/composer/package-versions-deprecated/blob/c6522afe5540d5fc46675043d3ed5a45a740b27c/test/PackageVersionsTest/E2EInstallerTest.php#L262-L301 - * - * @param string $source Path to the directory to package up. - * @param string $target Path to the file where to save the zip. - * @param string $version Version number to use for the package. - * - * @return void - */ - private function createZipArtifact($source, $target, $version) - { - if (file_exists($target) === true) { - @unlink($target); - } - - $zip = new ZipArchive(); - $zip->open($target, ZipArchive::CREATE); - - $directoryIterator = new RecursiveDirectoryIterator( - realpath($source), - RecursiveDirectoryIterator::SKIP_DOTS - ); - - $filteredFileIterator = new RecursiveIteratorIterator( - new RecursiveCallbackFilterIterator( - $directoryIterator, - function (SplFileInfo $file, $key, RecursiveDirectoryIterator $iterator) { - $subPathName = $iterator->getSubPathname(); - $extension = $file->getExtension(); - - return (isset($this->excludedFiles[$subPathName]) === false) - && isset($this->excludedExtensions[$extension]) === false - && isset($this->excludedDirs[$subPathName]) === false - && $subPathName[0] !== '.'; // Not a .dot-file. - } - ), - RecursiveIteratorIterator::LEAVES_ONLY - ); - - foreach ($filteredFileIterator as $file) { - if ($file->isFile() === false) { - continue; - } - - /* - * DO NOT REMOVE! - * While this block may seem unnecessary, adding an arbitrary version number in the composer.json - * file **IS** necessary for Composer installs via a repo artifact to actual work. - * This does not seem to be documented in the Composer documentation, but if the - * version is not declared in the composer.json of the artifact, the install will fail - * with a "Package ... has no version defined." exception. - */ - if ($file->getFilename() === 'composer.json') { - $contents = json_decode(file_get_contents($file->getRealPath()), true); - $contents['version'] = $version; - - $zip->addFromString( - 'composer.json', - json_encode($contents, \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT) - ); - - continue; - } - - $zip->addFile( - $file->getRealPath(), - str_replace('\\', '/', substr($file->getRealPath(), strlen(realpath($source)) + 1)) - ); - } - - $zip->close(); - } -} diff --git a/tests/DebugTestListener.php b/tests/DebugTestListener.php deleted file mode 100644 index b1a5264a..00000000 --- a/tests/DebugTestListener.php +++ /dev/null @@ -1,66 +0,0 @@ -getName(), \PHP_EOL, self::$debugLog; - } - } - - /** - * Add information to the debug log. - * - * @param string The information to add to the log. - * - * @return void - */ - public static function debugLog($str) - { - self::$debugLog .= $str . \PHP_EOL; - } -} diff --git a/tests/IntegrationTest/BaseLineTest.php b/tests/IntegrationTest/BaseLineTest.php deleted file mode 100644 index 3b57aaa6..00000000 --- a/tests/IntegrationTest/BaseLineTest.php +++ /dev/null @@ -1,178 +0,0 @@ - 'phpcs-composer-installer/baseline-test', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => null, - 'dealerdirect/phpcodesniffer-composer-installer' => '*', - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Baseline test for a Composer GLOBAL install. - * - * @dataProvider dataBaseLine - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * @param array $expectedStnds List of the standards which are expected to be registered. - * - * @return void - */ - public function testBaseLineGlobal($phpcsVersion, $expectedStnds) - { - $config = $this->composerConfig; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempGlobalPath); - $this->assertComposerValidates(static::$tempGlobalPath); - - // Make sure the plugin runs. - $this->assertExecute( - 'composer global install -v --no-ansi', - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - $result = $this->executeCliCommand('"vendor/bin/phpcs" -i', static::$tempGlobalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for phpcs -i did not match 0'); - $this->assertSame( - $expectedStnds, - $this->standardsPhraseToArray($result['stdout']), - 'Installed standards do not match the expected standards.' - ); - - // Make sure the CodeSniffer.conf file does not get created when no external standards are found. - $this->assertFileDoesNotExist( - static::$tempGlobalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf' - ); - } - - /** - * Baseline test for a Composer LOCAL install. - * - * @dataProvider dataBaseLine - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * @param array $expectedStnds List of the standards which are expected to be registered. - * - * @return void - */ - public function testBaseLineLocal($phpcsVersion, $expectedStnds) - { - if ( - $phpcsVersion === PHPCSVersions::MASTER - && \CLI_PHP_MINOR === '5.5' - && $this->onWindows() === true - && substr(\COMPOSER_VERSION, 0, 1) === '1' - ) { - $this->markTestSkipped( - 'Composer 1.x on Windows with PHP 5.5 does run the plugin when there are no external standards,' - . ' but doesn\'t consistently show this in the logs' - ); - } - - $config = $this->composerConfig; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempLocalPath); - $this->assertComposerValidates(static::$tempLocalPath); - - // Make sure the plugin runs. - $this->assertExecute( - sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - $result = $this->executeCliCommand('"vendor/bin/phpcs" -i', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for phpcs -i did not match 0'); - $this->assertSame( - $expectedStnds, - $this->standardsPhraseToArray($result['stdout']), - 'Installed standards do not match the expected standards.' - ); - - // Make sure the CodeSniffer.conf file does not get created when no external standards are found. - $this->assertFileDoesNotExist( - static::$tempLocalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf' - ); - } - - /** - * Data provider. - * - * Note: PHPCS does not display the names of the standards in a fixed order, so the order in which standards - * get displayed may differ depending on the machine/OS on which the tests get run. - * With that in mind, the verification that the PHPCS native standards are the only recognized standards - * is done using a regex instead of an exact match. - * Also see: https://github.com/squizlabs/PHP_CodeSniffer/pull/3539 - * - * @return array - */ - public function dataBaseLine() - { - // Get two PHPCS versions suitable for this PHP version + `master` + PHPCS 4.x dev. - $versions = PHPCSVersions::get(2, true, true); - - $data = array(); - foreach ($versions as $version) { - $data["phpcs $version"] = array( - 'phpcsVersion' => $version, - 'expectedStnds' => PHPCSVersions::getStandards($version), - ); - } - - return $data; - } -} diff --git a/tests/IntegrationTest/InstallUpdateEventsTest.php b/tests/IntegrationTest/InstallUpdateEventsTest.php deleted file mode 100644 index 66b1ee95..00000000 --- a/tests/IntegrationTest/InstallUpdateEventsTest.php +++ /dev/null @@ -1,327 +0,0 @@ - 'phpcs-composer-installer/plugin-events-test', - 'require-dev' => array( - 'dealerdirect/phpcodesniffer-composer-installer' => '*', - 'phpcs-composer-installer/dummy-subdir' => '*', - 'ehime/hello-world' => '^1.0', - ), - 'scripts' => array( - 'custom-runner' => array( - 'PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run', - ), - 'post-install-cmd' => array( - 'echo "post-install-cmd successfully run"', - ), - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test that the plugin runs when Composer is invoked with an action triggering a hooked in event. - * - * @dataProvider dataComposerActions - * - * @param string $action The Composer action to run. - * - * @return void - */ - public function testPluginRuns($action) - { - $this->writeComposerJsonFile($this->composerConfig, static::$tempLocalPath); - - $command = sprintf( - 'composer %s -v --no-ansi --working-dir=%s', - $action, - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - - $this->assertSame(0, $result['exitcode'], "Exitcode for composer $action did not match 0"); - $this->assertStringContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - "Output from composer $action does not show the plugin as running while it should be." - ); - } - - /** - * Data provider. - * - * @link https://getcomposer.org/doc/03-cli.md - * @link https://getcomposer.org/doc/articles/scripts.md#event-names - * - * @return array - */ - public function dataComposerActions() - { - return array( - 'install' => array('install'), - 'update' => array('update'), - 'require' => array('require --dev phpcs-composer-installer/dummy-src'), - 'remove' => array('remove --dev ehime/hello-world'), - ); - - $data = array(); - foreach ($actions as $action) { - $data[$action] = array($action); - } - - return $data; - } - - /** - * Test that the plugin runs when Composer reinstall is run for a project - * with a require(-dev) for the plugin. - * - * @link https://github.com/composer/composer/issues/10508 - * - * @return void - */ - public function testPluginRunsOnReinstall() - { - if (version_compare(\COMPOSER_VERSION, '2.2.6', '<') === true) { - $this->markTestSkipped('Plugins don\'t run on reinstall prior to Composer 2.2.6 - Composer bug #10508'); - } - - $this->writeComposerJsonFile($this->composerConfig, static::$tempLocalPath); - - /* - * 1. Can only reinstall on something which is already installed, so install first. - */ - $command = sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)); - $result = $this->executeCliCommand($command); - $this->assertSame(0, $result['exitcode'], 'Exitcode for composer install did not match 0'); - - // Track what installed standards this resulted in. - $installedPaths = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $installedPaths['exitcode'], 'Exitcode for "--config-show" did not match 0 (install)'); - - /* - * 2. Reinstall PHPCS. - */ - $command = sprintf( - 'composer reinstall squizlabs/php_codesniffer -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - $this->assertSame(0, $result['exitcode'], 'Exitcode for composer reinstall did not match 0'); - - // Verify the plugin ran. - $this->assertStringContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - "Output from composer reinstall does not show the plugin as running while it should be." - ); - - /* - * 3. Ensure the installed paths are the same before and after the reinstall. - */ - $reinstalledPaths = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $reinstalledPaths['exitcode'], 'Exitcode for "--config-show" did not match 0 (reinstall)'); - - $expected = $this->configShowToPathsArray($installedPaths['stdout']); - $actual = $this->configShowToPathsArray($reinstalledPaths['stdout']); - - // Verify that the same paths are registered on install as well as reinstall. - $this->assertSame($expected, $actual); - } - - /** - * Test that the plugin runs (or doesn't run) when Composer is invoked with the --no-scripts argument. - * - * Note: the behaviour of Composer changed in 2.1.2. Prior to that, `--no-scripts` would - * also stop plugins from running. As of Composer 2.1.2, `--no-scripts` and `--no-plugins` - * function independently of each other. - * {@link https://github.com/composer/composer/pull/9942} - * - * @return void - */ - public function testPluginRunsOnInstallWithNoScripts() - { - $this->writeComposerJsonFile($this->composerConfig, static::$tempLocalPath); - - $command = sprintf( - 'composer install --no-scripts -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for composer install did not match 0'); - - if (version_compare(\COMPOSER_VERSION, '2.1.2', '>=') === true) { - $this->assertStringContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from running Composer install missing expected contents.' - ); - } else { - // Composer 1.x. - $this->assertStringNotContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from running Composer install contains unexpected contents.' - ); - } - } - - /** - * Test that the plugin doesn't run when Composer init is run with a require for the plugin - * (as that doesn't install anything yet). - * - * Note: this test "should" be in the NonInstallUpdateEventsTest, but it requires a clean environment, - * so it ended up being more straight-forward to include it in this test class. - * - * @return void - */ - public function testPluginDoesNotRunsOnInitWithRequire() - { - $command = sprintf( - 'composer init' - . ' --name=phpcs-composer-installer/plugin-events-init-test' - . ' --type=project' - . ' --require-dev=dealerdirect/phpcodesniffer-composer-installer:*,phpcs-composer-installer/dummy-subdir:*' - . ' -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for composer init did not match 0'); - - $this->assertStringNotContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from composer init shows the plugin as running when it shouldn\'t be.' - ); - } - - /** - * Test that the plugin does not run when Composer is invoked with the --no-plugins argument. - * - * @return void - */ - public function testPluginDoesNotRunOnInstallWithNoPlugins() - { - $this->writeComposerJsonFile($this->composerConfig, static::$tempLocalPath); - - // Verify the plugin doesn't run when install is run with --no-plugins. - $command = sprintf( - 'composer install --no-plugins -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for composer install did not match 0'); - - $this->assertStringNotContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from composer install shows the plugin as running when it shouldn\'t .' - ); - - // Verify the plugin doesn't run when post-install-cmd is run with --no-plugins. - $command = sprintf( - 'composer run-script post-install-cmd --no-plugins -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for composer post-install-cmd did not match 0'); - - $this->assertStringNotContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from composer post-install-cmd shows the plugin as running when it shouldn\'t be.' - ); - } - - /** - * Test that the plugin does not run when Composer is invoked with the --no-plugins AND --no-scripts arguments, - * but can then still be invoked via a custom script. - * - * @return void - */ - public function testPluginDoesNotRunWithNoScriptsNoPluginsAndRunsViaScript() - { - $this->writeComposerJsonFile($this->composerConfig, static::$tempLocalPath); - - // Verify the plugin doesn't run when install is run with --no-plugins and --no-scripts. - $command = sprintf( - 'composer install --no-scripts --no-plugins -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for composer install did not match 0'); - - $this->assertStringNotContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from composer install shows the plugin as running when it shouldn\'t be.' - ); - - // Verify that the plugin can be run via a custom script. - $script = sprintf( - 'composer custom-runner -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($script); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for running Composer script did not match 0'); - - $this->assertStringContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from running Composer script missing expected contents.' - ); - } -} diff --git a/tests/IntegrationTest/InstalledPathsOrderTest.php b/tests/IntegrationTest/InstalledPathsOrderTest.php deleted file mode 100644 index 070f37e7..00000000 --- a/tests/IntegrationTest/InstalledPathsOrderTest.php +++ /dev/null @@ -1,127 +0,0 @@ - 'phpcs-composer-installer/sort-order-test', - 'require-dev' => array( - 'phpcs-composer-installer/dummy-subdir' => '*', - 'phpcs-composer-installer/multistandard' => '*', - 'phpcs-composer-installer/dummy-src' => '*', - ), - 'minimum-stability' => 'dev', - 'prefer-stable' => true, - ); - - private $composerConfigB = array( - 'name' => 'phpcs-composer-installer/sort-order-test', - 'require-dev' => array( - 'phpcs-composer-installer/multistandard' => '*', - 'phpcs-composer-installer/dummy-src' => '*', - 'phpcs-composer-installer/dummy-subdir' => '*', - ), - 'minimum-stability' => 'dev', - 'prefer-stable' => true, - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test that the paths registered through the plugin are always registered in the same (sort) order. - * - * @return void - */ - public function testInstalledPathsAreAlwaysRegisteredInSameOrder() - { - /* - * 1. Install using ConfigA in the Composer global directory. - */ - $this->writeComposerJsonFile($this->composerConfigA, static::$tempGlobalPath); - - // Make sure the plugin runs. - $this->assertExecute( - 'composer global install -v --no-ansi', - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * 2. Install using ConfigB in the Composer local directory. - */ - $this->writeComposerJsonFile($this->composerConfigB, static::$tempLocalPath); - - // Make sure the plugin runs. - $this->assertExecute( - sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * 3. Retrieve the installed paths from both and compare to ensure the order is the same. - */ - $globalPaths = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempGlobalPath); - $this->assertSame(0, $globalPaths['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (global)'); - - $localPaths = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $localPaths['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (local)'); - - // Get the installed paths setting from the config. - $this->assertSame( - 1, - preg_match('`installed_paths:\s+([^\n\r]+)\s+`', $globalPaths['stdout'], $matchGlobal), - 'Could not find "installed_paths" in the config-show output (global)' - ); - $this->assertSame( - 1, - preg_match('`installed_paths:\s+([^\n\r]+)\s+`', $localPaths['stdout'], $matchLocal), - 'Could not find "installed_paths" in the config-show output (local)' - ); - - // Remove any differences caused by global vs local paths and absolute vs relative paths. - $matchGlobal = str_replace(array(static::$tempGlobalPath . '/vendor', '../..'), '', $matchGlobal[1]); - $matchLocal = str_replace(array(static::$tempLocalPath . '/vendor', '../..'), '', $matchLocal[1]); - - // Verify that the paths are registered in the same order both times. - $this->assertSame($matchGlobal, $matchLocal, 'Order of paths in "installed_paths" is not the same'); - } -} diff --git a/tests/IntegrationTest/InvalidPackagesTest.php b/tests/IntegrationTest/InvalidPackagesTest.php deleted file mode 100644 index 1a0e9044..00000000 --- a/tests/IntegrationTest/InvalidPackagesTest.php +++ /dev/null @@ -1,116 +0,0 @@ - 'phpcs-composer-installer/invalid-package-no-ruleset-test', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => '*', - 'phpcs-composer-installer/no-ruleset' => '*', - ), - ); - - private $composerConfigIncorrectType = array( - 'name' => 'phpcs-composer-installer/invalid-package-incorrect-type-test', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => '*', - 'phpcs-composer-installer/incorrect-type' => '*', - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test that the plugin does not set the installed_paths for invalid external PHPCS standards. - * - * @dataProvider dataInvalidPackages - * - * @param array $config The Composer configuration to use. - * @param string $standardName The name of the PHPCS standard which is expected to NOT be registered. - * - * @return void - */ - public function testDontSetInstalledPathsForInvalidPackages($config, $standardName) - { - $this->writeComposerJsonFile($config, static::$tempLocalPath); - - // Make sure the plugin runs. - $this->assertExecute( - sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - // Make sure the CodeSniffer.conf file does not get created when no (valid) external standards are found. - $this->assertFileDoesNotExist( - static::$tempLocalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf' - ); - - // Make sure that the standard does not show up as registered with PHPCS. - $result = $this->executeCliCommand('"vendor/bin/phpcs" -i', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for phpcs -i did not match 0'); - $this->assertStringNotContainsString( - $standardName, - $result['stdout'], - 'Invalid standard registered.' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function dataInvalidPackages() - { - return array( - 'Composer package without ruleset file' => array( - 'configName' => $this->composerConfigNoRuleset, - 'standardName' => 'NoRuleset', - ), - 'Composer package with incorrect type' => array( - 'configName' => $this->composerConfigIncorrectType, - 'standardName' => 'IncorrectType', - ), - ); - } -} diff --git a/tests/IntegrationTest/NonInstallUpdateEventsTest.php b/tests/IntegrationTest/NonInstallUpdateEventsTest.php deleted file mode 100644 index 7556627e..00000000 --- a/tests/IntegrationTest/NonInstallUpdateEventsTest.php +++ /dev/null @@ -1,136 +0,0 @@ - 'phpcs-composer-installer/non-plugin-events-test', - 'require-dev' => array( - 'dealerdirect/phpcodesniffer-composer-installer' => '*', - 'phpcs-composer-installer/dummy-subdir' => '*', - ), - ); - - /** - * Set up test environment at the start of the tests. - */ - public static function set_up_before_class() - { - static::createTestEnvironment(); - - static::writeComposerJsonFile(self::$composerConfig, static::$tempLocalPath); - - /* - * Install dependencies. - * As the commands being run in these tests don't _change_ the environment, we only need to do this once. - */ - $command = sprintf( - 'composer install --no-plugins --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = static::executeCliCommand($command); - - if ($result['exitcode'] !== 0) { - throw new RuntimeException('`composer install` failed'); - } - } - - /** - * Clean up after all tests have run. - */ - public static function tear_down_after_class() - { - static::removeTestEnvironment(); - } - - /** - * Test that the plugin doesn't run on commands for which it shouldn't. - * - * @dataProvider dataComposerActions - * - * @param string $action The Composer action to run. - * - * @return void - */ - public function testPluginDoesNotRun($action) - { - $command = sprintf( - 'composer %s -v --no-ansi --working-dir=%s', - $action, - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($command); - - $this->assertStringNotContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - "Output from composer $action shows the plugin as running when it shouldn't be." - ); - } - - /** - * Data provider. - * - * @link https://getcomposer.org/doc/03-cli.md - * @link https://getcomposer.org/doc/articles/scripts.md#event-names - * - * @return array - */ - public function dataComposerActions() - { - $actions = array( - /* - * Composer actions which actually have events associated with them, - * but which the plugin is not hooked into. - */ - 'archive', - 'dump-autoload', - 'status', - - /* - * Composer actions which don't have events associated with them (just to be sure). - */ - 'check-platform-reqs', - 'config --list', - 'depends', - 'diagnose', - 'fund', - 'help', - 'licenses', - 'outdated', - 'prohibits', - 'search dealerdirect', - 'show', - 'suggests', - 'validate', - - // Excluded to prevent influencing other tests as the Composer version is important for most tests. - //'self-update', - ); - - $data = array(); - foreach ($actions as $action) { - $data[$action] = array($action); - } - - return $data; - } -} diff --git a/tests/IntegrationTest/PlayNiceWithScriptsTest.php b/tests/IntegrationTest/PlayNiceWithScriptsTest.php deleted file mode 100644 index 2cd2f08b..00000000 --- a/tests/IntegrationTest/PlayNiceWithScriptsTest.php +++ /dev/null @@ -1,163 +0,0 @@ - 'phpcs-composer-installer/dont-block-scripts-test', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => '*', - 'dealerdirect/phpcodesniffer-composer-installer' => '*', - 'phpcs-composer-installer/dummy-subdir' => '*', - ), - 'scripts' => array( - 'post-install-cmd' => array( - 'echo "post-install-cmd successfully run"', - ), - 'post-update-cmd' => array( - 'echo "post-update-cmd successfully run"', - ), - 'install-codestandards' => array( - 'PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run', - 'echo "install-codestandards successfully run"', - ), - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test that the plugin does not block other post install/update scripts from running. - * - * @dataProvider dataScriptsAreNotBlockedFromRunning - * - * @param string $secondCommand The command to run after the initial install has been done. - * @param array $expectedOutputs Phrases which are expected to be included in the stdout for the second command. - * - * @return void - */ - public function testScriptsAreNotBlockedFromRunning($command, $expectedOutputs) - { - $this->writeComposerJsonFile($this->composerConfig, static::$tempLocalPath); - - /* - * 1. Run an install, all should be fine to begin with. - */ - $installCommand = sprintf( - 'composer install -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $result = $this->executeCliCommand($installCommand); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for initial composer install did not match 0'); - - $this->assertStringContainsString( - Plugin::MESSAGE_RUNNING_INSTALLER, - $result['stdout'], - 'Output from initial composer install missing expected contents.' - ); - - $this->assertStringContainsString( - 'post-update-cmd successfully run', - $result['stdout'], - 'Output from initial composer install missing expected contents.' - ); - - /* - * 2. Run the second command to confirm scripts are not blocked. - */ - $command = sprintf('%s -v --no-ansi --working-dir=%s', $command, escapeshellarg(static::$tempLocalPath)); - $result = $this->executeCliCommand($command); - - $this->assertSame(0, $result['exitcode'], 'Exitcode for secondary command did not match 0'); - - foreach ($expectedOutputs as $expected) { - $this->assertStringContainsString( - $expected, - $result['stdout'], - 'Output from secondary command missing expected contents.' - ); - } - } - - /** - * Data provider. - * - * @return array - */ - public function dataScriptsAreNotBlockedFromRunning() - { - return array( - 'install:command' => array( - 'command' => 'composer install', - 'expectedOutputs' => array( - 'post-install-cmd successfully run', - Plugin::MESSAGE_RUNNING_INSTALLER, - ), - ), - 'update:command' => array( - 'command' => 'composer update', - 'expectedOutputs' => array( - 'post-update-cmd successfully run', - Plugin::MESSAGE_RUNNING_INSTALLER, - ), - ), - 'post-install-cmd:script' => array( - 'command' => 'composer run-script post-install-cmd', - 'expectedOutputs' => array( - Plugin::MESSAGE_RUNNING_INSTALLER, - 'post-install-cmd successfully run', - ), - ), - 'post-update-cmd:script' => array( - 'command' => 'composer run-script post-update-cmd', - 'expectedOutputs' => array( - Plugin::MESSAGE_RUNNING_INSTALLER, - 'post-update-cmd successfully run', - ), - ), - 'install-codestandards:script' => array( - 'command' => 'composer run-script install-codestandards', - 'expectedOutputs' => array( - Plugin::MESSAGE_RUNNING_INSTALLER, - 'install-codestandards successfully run', - ), - ), - ); - } -} diff --git a/tests/IntegrationTest/PreexistingPHPCSConfigTest.php b/tests/IntegrationTest/PreexistingPHPCSConfigTest.php deleted file mode 100644 index f02e3dc5..00000000 --- a/tests/IntegrationTest/PreexistingPHPCSConfigTest.php +++ /dev/null @@ -1,182 +0,0 @@ - 'phpcs-composer-installer/preexisting-config-test', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => null, - 'dealerdirect/phpcodesniffer-composer-installer' => '*', - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test correctly handling a pre-existing PHPCS configuration file (which doesn't involve - * a pre-existing `installed_paths` setting). - * - * @dataProvider dataPHPCSVersions - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * - * @return void - */ - public function testPreexistingNonInstalledPathsConfigIsKeptIntact($phpcsVersion) - { - $config = $this->composerConfig; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempLocalPath); - - /* - * 1. Install PHPCS and the plugin. - */ - $this->assertExecute( - sprintf('composer install -v --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - null, // No stdout expectation. - null, // No stderr expectation. - 'Failed to install PHPCS.' - ); - - // Verify the CodeSniffer.conf file does not exist to start with. - $this->assertFileDoesNotExist( - static::$tempLocalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf' - ); - - // Verify that the config is empty to start with. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (first run)'); - $this->assertMatchesRegularExpression( - '`^\s*(Using config file:)?\s*$`', - $result['stdout'], - 'PHPCS configuration is not empty to start with.' - ); - - /* - * 2. Set some configs and verify they are registered correctly. - * - * Note: PHPCS will "show" the config settings in alphabetic order. - * These settings have been chosen to ensure there will be settings to show - * both before *and* after the `installed_paths` setting. - */ - $command = '"vendor/bin/phpcs" --config-set %s %s'; - $failureMsg = 'Exitcode for "phpcs --config-set %s %s" did not match 0'; - $settings = array( - 'default_standard' => 'PSR12', - 'colors' => '1', - 'show_progress' => '1', - ); - - foreach ($settings as $name => $value) { - $result = $this->executeCliCommand(sprintf($command, $name, $value), static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], sprintf($failureMsg, $name, $value)); - } - - // Make sure the CodeSniffer.conf file has been created. - $this->assertFileExists( - static::$tempLocalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf' - ); - - // Verify that the config contains the newly set values. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (second run)'); - - $regex = '`colors:\s+1\s+' - . 'default_standard:\s+PSR12\s+' - . 'show_progress:\s+1\s*$`'; - $this->assertMatchesRegularExpression( - $regex, - $result['stdout'], - 'PHPCS configuration does not show the newly set values correctly.' - ); - - /* - * 3. Install an external standard. - */ - $command = sprintf( - 'composer require --dev phpcs-composer-installer/dummy-subdir --no-ansi -v --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $this->assertExecute( - $command, - 0, // Expected exit code. - 'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout. - null, // No stderr expectation. - 'Failed to install Dummy subdir standard.' - ); - - // Verify that the originally set configs are retained and the standard is registered correctly. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (third run)'); - - $regex = '`colors:\s+1\s+' - . 'default_standard:\s+PSR12\s+' - . 'installed_paths:\s+[^\n\r]+/phpcs-composer-installer/dummy-subdir\s+' - . 'show_progress:\s+1\s*$`'; - $this->assertMatchesRegularExpression( - $regex, - $result['stdout'], - 'PHPCS configuration has not been retained and/or updated correctly.' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function dataPHPCSVersions() - { - // Test against the highest and lowest supported PHPCS version for each major + `master` + PHPCS 4.x dev. - $versions = PHPCSVersions::getHighLowEachMajor(true, true); - return PHPCSVersions::toDataprovider($versions); - } -} diff --git a/tests/IntegrationTest/PreexistingPHPCSInstalledPathsConfigTest.php b/tests/IntegrationTest/PreexistingPHPCSInstalledPathsConfigTest.php deleted file mode 100644 index 10411e47..00000000 --- a/tests/IntegrationTest/PreexistingPHPCSInstalledPathsConfigTest.php +++ /dev/null @@ -1,291 +0,0 @@ - 'phpcs-composer-installer/preexisting-config-test', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => null, - 'dealerdirect/phpcodesniffer-composer-installer' => '*', - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - - /* - * Create an extra directory in the test environment, but outside of the directory used - * in the test (where Composer is run) and copy an external standard fixture to it. - */ - $this->tempExtraStndsPath = static::$tempDir . $this->tempExtraStndsSubdir; - - // Create all needed subdirectories in one go. - $path = $this->tempExtraStndsPath . '/DummySubDir'; - if (mkdir($path, 0766, true) === false || is_dir($path) === false) { - throw new RuntimeException("Failed to create the $path directory for the test"); - } - - // We only need the ruleset.xml file for the standard to be valid. - copy( - dirname(__DIR__) . '/fixtures/dummy-subdir/DummySubDir/ruleset.xml', - $this->tempExtraStndsPath . '/DummySubDir/ruleset.xml' - ); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test correctly handling a pre-existing PHPCS configuration file which includes a pre-set, - * valid `installed_paths`. - * - * @dataProvider dataPHPCSVersions - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * - * @return void - */ - public function testPreexistingValidInstalledPathsConfigIsKeptIntact($phpcsVersion) - { - $config = $this->composerConfig; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempGlobalPath); - - /* - * 1. Install PHPCS and the plugin. - */ - $this->assertExecute( - 'composer global install', - 0, // Expected exit code. - null, // No stdout expectation. - null, // No stderr expectation. - 'Failed to install PHPCS.' - ); - - /* - * 2. Set the installed_paths and verify it is registered correctly. - */ - $command = sprintf( - '"vendor/bin/phpcs" --config-set installed_paths %s', - escapeshellarg($this->tempExtraStndsPath) - ); - $result = $this->executeCliCommand($command, static::$tempGlobalPath); - $this->assertSame( - 0, - $result['exitcode'], - 'Exitcode for "phpcs --config-set installed_paths" did not match 0' - ); - - // Verify that the config contains the newly set value. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempGlobalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (first run)'); - - $expected = array( - $this->tempExtraStndsPath, - ); - - $this->assertSame( - $expected, - $this->configShowToPathsArray($result['stdout']), - 'PHPCS configuration does not show the manually set installed_paths correctly' - ); - - /* - * 3. Install an external standard. - */ - $command = 'composer global require --dev phpcs-composer-installer/dummy-subdir --no-ansi -v'; - $this->assertExecute( - $command, - 0, // Expected exit code. - 'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout. - null, // No stderr expectation. - 'Failed to install Dummy subdir standard.' - ); - - // Verify that the originally set path is retained and the new standard is registered correctly as well. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempGlobalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (second run)'); - - - $expected = array( - $this->tempExtraStndsPath, - '/phpcs-composer-installer/dummy-subdir', - ); - sort($expected, \SORT_NATURAL); - - $this->assertSame( - $expected, - $this->configShowToPathsArray($result['stdout']), - 'Paths as updated by the plugin does not contain the expected paths' - ); - } - - /** - * Test correctly handling a pre-existing PHPCS configuration file which includes both - * a pre-set, valid path, as well as an invalid path in `installed_paths`. - * - * @dataProvider dataPHPCSVersions - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * - * @return void - */ - public function testPreexistingInvalidInstalledPathsConfigIsRemoved($phpcsVersion) - { - $config = $this->composerConfig; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempLocalPath); - - /* - * 1. Install PHPCS and the plugin. - */ - $this->assertExecute( - sprintf('composer install -v --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - null, // No stdout expectation. - null, // No stderr expectation. - 'Failed to install PHPCS.' - ); - - /* - * 2. Set the installed_paths and verify it is registered correctly. - */ - $command = sprintf( - '"vendor/bin/phpcs" --config-set installed_paths %s', - escapeshellarg($this->tempExtraStndsPath) - ); - $result = $this->executeCliCommand($command, static::$tempLocalPath); - $this->assertSame( - 0, - $result['exitcode'], - 'Exitcode for "phpcs --config-set installed_paths" did not match 0' - ); - - /* - * Manipulate the value of installed_paths as registered in PHPCS. - * - * Note: for the test we do this "manually". In real life, this may be a standard which - * used to be installed, but was removed without the installed_paths having been updated - * in PHPCS (prior to the plugin being used). - * - * Also note: depending on the OS and the PHP version, passing an invalid path to `--config-set` - * will error on an exception from the DirectoryIterator as used by PHPCS itself. - * The manual setting prevents this exception, but still allows us to test this use-case. - */ - $confFile = static::$tempLocalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf'; - $confContents = file_get_contents($confFile); - $this->assertNotFalse($confContents); - $confContents = str_replace( - $this->tempExtraStndsSubdir, - $this->tempExtraStndsSubdir . ',path/to/somecloned-stnd', - $confContents - ); - $this->assertNotFalse(file_put_contents($confFile, $confContents)); - - // Verify that the config contains the newly set value. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (first run)'); - - $expected = array( - $this->tempExtraStndsPath, - 'path/to/somecloned-stnd', - ); - sort($expected, \SORT_NATURAL); - - $this->assertSame( - $expected, - $this->configShowToPathsArray($result['stdout']), - 'PHPCS configuration does not show the manually set installed_paths correctly' - ); - - /* - * 3. Install an external standard. - */ - $command = sprintf( - 'composer require --dev phpcs-composer-installer/dummy-subdir --no-ansi -v --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $this->assertExecute( - $command, - 0, // Expected exit code. - 'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout. - null, // No stderr expectation. - 'Failed to install Dummy subdir standard.' - ); - - /* - * Verify that the valid preset path is retained, that the invalid path is removed - * and the new standard is registered correctly. - */ - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (second run)'); - - $expected = array( - $this->tempExtraStndsPath, - '/phpcs-composer-installer/dummy-subdir', - ); - sort($expected, \SORT_NATURAL); - - $this->assertSame( - $expected, - $this->configShowToPathsArray($result['stdout']), - 'Paths as updated by the plugin does not contain the expected paths' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function dataPHPCSVersions() - { - // Test against the highest and lowest supported PHPCS version for each major + `master` + PHPCS 4.x dev. - $versions = PHPCSVersions::getHighLowEachMajor(true, true); - return PHPCSVersions::toDataprovider($versions); - } -} diff --git a/tests/IntegrationTest/RegisterExternalStandardsTest.php b/tests/IntegrationTest/RegisterExternalStandardsTest.php deleted file mode 100644 index 3604c886..00000000 --- a/tests/IntegrationTest/RegisterExternalStandardsTest.php +++ /dev/null @@ -1,343 +0,0 @@ - 'phpcs-composer-installer/register-external-stnds-one-stnd', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => null, - 'phpcs-composer-installer/dummy-subdir' => '*', - 'dealerdirect/phpcodesniffer-composer-installer' => '*', - ), - ); - - private $configOneStandardMultiRuleset = array( - 'name' => 'phpcs-composer-installer/register-external-stnds-multistnd', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => null, - 'phpcs-composer-installer/multistandard' => '*', - ), - ); - - private $configOneStandardInSrcSubdir = array( - 'name' => 'phpcs-composer-installer/register-external-stnds-in-src-subdir', - 'require-dev' => array( - 'squizlabs/php_codesniffer' => null, - 'phpcs-composer-installer/dummy-src' => '*', - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test registering one external standard for a Composer GLOBAL install. - * - * @dataProvider dataRegisterOneStandard - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * - * @return void - */ - public function testRegisterOneStandardGlobal($phpcsVersion) - { - $config = $this->configOneStandard; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempGlobalPath); - $this->assertComposerValidates(static::$tempGlobalPath); - - // Install the dependencies. - $this->assertExecute( - 'composer global install --no-plugins', - 0, // Expected exit code. - null, // No stdout expectation. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - // Verify that the standard registers correctly. - $installResult = $this->executeCliCommand('composer global install-codestandards --no-ansi'); - $this->assertSame(0, $installResult['exitcode'], 'Exitcode for install-codestandards did not match 0'); - - $this->assertMatchesRegularExpression( - '`^PHP CodeSniffer Config installed_paths set to [^\s]+/dummy-subdir$`', - trim($installResult['stdout']), - 'Installing the standards failed.' - ); - - // Make sure the CodeSniffer.conf file has been created. - $this->assertFileExists( - static::$tempGlobalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf' - ); - - // Verify that PHPCS sees the external standard. - $this->assertExecute( - '"vendor/bin/phpcs" -i', - 0, // Expected exit code. - 'and DummySubDir', // Expected stdout. - '', // Empty stderr expectation. - 'Running phpcs -i failed.', - static::$tempGlobalPath - ); - - // Verify that PHPCS can with the external standard set as the standard. - $phpcsCommand = '"vendor/bin/phpcs" --standard=DummySubDir -e'; - $phpcsResult = $this->executeCliCommand($phpcsCommand, static::$tempGlobalPath); - - $this->assertSame(0, $phpcsResult['exitcode'], 'Exitcode for PHPCS explain did not match 0'); - $this->assertMatchesRegularExpression( - '`DummySubDir \(1 sniffs?\)\s+[-]+\s+DummySubDir\.Demo\.Demo(?:[\r\n]+|$)`', - $phpcsResult['stdout'], - 'Output of the PHPCS explain command did not match the expectation.' - ); - } - - /** - * Test registering one external standard for a Composer LOCAL install. - * - * @dataProvider dataRegisterOneStandard - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * - * @return void - */ - public function testRegisterOneStandardLocal($phpcsVersion) - { - $config = $this->configOneStandard; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempLocalPath); - $this->assertComposerValidates(static::$tempLocalPath); - - // Install the dependencies. - $this->assertExecute( - sprintf('composer install --no-plugins --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - null, // No stdout expectation. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - // Verify that the standard registers correctly. - $installCommand = sprintf( - 'composer install-codestandards --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $installResult = $this->executeCliCommand($installCommand); - $this->assertSame(0, $installResult['exitcode'], 'Exitcode for install-codestandards did not match 0'); - - $this->assertMatchesRegularExpression( - '`^PHP CodeSniffer Config installed_paths set to [^\s]+/dummy-subdir$`', - trim($installResult['stdout']), - 'Installing the standards failed.' - ); - - // Make sure the CodeSniffer.conf file has been created. - $this->assertFileExists( - static::$tempLocalPath . '/vendor/squizlabs/php_codesniffer/CodeSniffer.conf' - ); - - // Verify that PHPCS sees the external standard. - $this->assertExecute( - '"vendor/bin/phpcs" -i', - 0, // Expected exit code. - 'and DummySubDir', // Expected stdout. - '', // Empty stderr expectation. - 'Running phpcs -i failed.', - static::$tempLocalPath - ); - - // Verify that PHPCS can with the external standard set as the standard. - $phpcsCommand = '"vendor/bin/phpcs" --standard=DummySubDir -e'; - $phpcsResult = $this->executeCliCommand($phpcsCommand, static::$tempLocalPath); - - $this->assertSame(0, $phpcsResult['exitcode'], 'Exitcode for PHPCS explain did not match 0'); - $this->assertMatchesRegularExpression( - '`DummySubDir \(1 sniffs?\)\s+[-]+\s+DummySubDir\.Demo\.Demo(?:[\r\n]+|$)`', - $phpcsResult['stdout'], - 'Output of the PHPCS explain command did not match the expectation.' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function dataRegisterOneStandard() - { - // Get two PHPCS versions suitable for this PHP version + `master` + PHPCS 4.x dev. - $versions = PHPCSVersions::get(2, true, true); - return PHPCSVersions::toDataprovider($versions); - } - - /** - * Test registering one external standard with multiple rulesets. - * - * @dataProvider dataRegisterOneStandardMultipleRulesets - * - * @param string $phpcsVersion PHPCS version to use in this test. - * This version is randomly selected from the PHPCS versions compatible - * with the PHP version used in the test. - * - * @return void - */ - public function testRegisterOneStandardWithMultipleRulesets($phpcsVersion) - { - $config = $this->configOneStandardMultiRuleset; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempLocalPath); - - // Install the dependencies and verify that the plugin has run. - $this->assertExecute( - sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - 'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - // Verify that only the one path is registered. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0'); - - $expected = array( - '/phpcs-composer-installer/multistandard', - ); - - $this->assertSame( - $expected, - $this->configShowToPathsArray($result['stdout']), - 'Paths as updated by the plugin does not contain the expected path' - ); - - // Verify that PHPCS sees all three external standards. - $result = $this->executeCliCommand('"vendor/bin/phpcs" -i', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs -i" did not match 0'); - - $expected = PHPCSVersions::getStandards($phpcsVersion); - $expected[] = 'MyFirstStandard'; - $expected[] = 'MySecondStandard'; - $expected[] = 'My-Third-Standard'; - sort($expected, \SORT_NATURAL); - - $this->assertSame( - $expected, - $this->standardsPhraseToArray($result['stdout']), - 'Installed standards do not match the expected standards.' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function dataRegisterOneStandardMultipleRulesets() - { - // Test against the highest and lowest supported PHPCS version of each major + PHPCS 4.x dev. - $versions = PHPCSVersions::getHighLowEachMajor(false, true); - return PHPCSVersions::toDataprovider($versions); - } - - /** - * Test registering an external standard which has the ruleset in a subdirectory nested in `src`. - * - * @dataProvider dataRandomPHPCSVersion - * - * @param string $phpcsVersion PHPCS version to use in this test. - * - * @return void - */ - public function testRegisterOneStandardInSrcSubdir($phpcsVersion) - { - $config = $this->configOneStandardInSrcSubdir; - $config['require-dev']['squizlabs/php_codesniffer'] = $phpcsVersion; - - $this->writeComposerJsonFile($config, static::$tempGlobalPath); - - // Install the dependencies and verify that the plugin has run. - $this->assertExecute( - 'composer global install -v --no-ansi', - 0, // Expected exit code. - 'PHP CodeSniffer Config installed_paths set to ', // Expectation for stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - // Verify that the path for the directory above the ruleset is registered. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempGlobalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0'); - - $expected = array( - '/phpcs-composer-installer/dummy-src/src', - ); - - $this->assertSame( - $expected, - $this->configShowToPathsArray($result['stdout']), - 'Paths as updated by the plugin does not contain the expected path' - ); - - // Verify that PHPCS sees the external standard. - $result = $this->executeCliCommand('"vendor/bin/phpcs" -i', static::$tempGlobalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs -i" did not match 0'); - - $expected = PHPCSVersions::getStandards($phpcsVersion); - $expected[] = 'DummySrcSubDir'; - sort($expected, \SORT_NATURAL); - - $this->assertSame( - $expected, - $this->standardsPhraseToArray($result['stdout']), - 'Installed standards do not match the expected standards.' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function dataRandomPHPCSVersion() - { - // Test against one random PHPCS version. - $versions = array(PHPCSVersions::getRandom(true, true)); - return PHPCSVersions::toDataprovider($versions); - } -} diff --git a/tests/IntegrationTest/RemovePluginTest.php b/tests/IntegrationTest/RemovePluginTest.php deleted file mode 100644 index 02ffd0c1..00000000 --- a/tests/IntegrationTest/RemovePluginTest.php +++ /dev/null @@ -1,281 +0,0 @@ - 'phpcs-composer-installer/remove-phpcs-test', - 'require-dev' => array( - 'phpcs-composer-installer/multistandard' => '*', - ), - ); - - private $composerConfigRequire = array( - 'name' => 'phpcs-composer-installer/remove-phpcs-test', - 'require' => array( - 'phpcs-composer-installer/multistandard' => '*', - ), - ); - - /** - * Set up test environment before each test. - */ - protected function set_up() - { - $this->createTestEnvironment(); - } - - /** - * Clean up after each test. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Helper method to get the stdout expectation for when the plugin is uninstalled. - * - * As of Composer 2.0.0, plugins which have been uninstalled will not run anymore - * after the uninstall (which is good). - * It is unclear which particular change this can be attributed to. - * - * @return string - */ - private function getUninstallStdOutExpectation() - { - if (strpos(\COMPOSER_VERSION, '1') === 0) { - return Plugin::MESSAGE_PLUGIN_UNINSTALLED; - } - - return ''; - } - - /** - * Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when PHPCS and the plugin - * were installed via --dev and a no-dev install is run, which removes the plugin and PHPCS. - * - * @return void - */ - public function testRemovePHPCSViaNoDevGlobal() - { - $this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempGlobalPath); - - // Install dependencies and make sure the plugin runs. - $this->assertExecute( - 'composer global install -v --no-ansi', - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * Switch to a no-dev install, which should remove the plugin, but the - * plugin will still be loaded in memory, so we need to make sure it doesn't - * throw errors. - */ - $this->assertExecute( - 'composer global install --no-dev -v --no-ansi', - 0, // Expected exit code. - $this->getUninstallStdOutExpectation(), // Expected stdout. - null, // No stderr expectation. - 'Uninstall by switching to no-dev did not meet expectations.' - ); - } - - /** - * Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when PHPCS and the plugin - * were installed via --dev and a no-dev install is run, which removes the plugin and PHPCS. - * - * @return void - */ - public function testRemovePHPCSViaNoDevLocal() - { - $this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempLocalPath); - - // Install dependencies and make sure the plugin runs. - $this->assertExecute( - sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * Switch to a no-dev install, which should remove the plugin, but the - * plugin will still be loaded in memory, so we need to make sure it exits with 0. - */ - $this->assertExecute( - sprintf('composer install --no-dev -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - $this->getUninstallStdOutExpectation(), // Expected stdout. - null, // No stderr expectation. - 'Uninstall by switching to no-dev did not meet expectations.' - ); - } - - /** - * Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS - * and the plugin when installed via require-dev by removing the dependency which installed it. - * - * @return void - */ - public function testRemovePHPCSViaDevUninstallGlobal() - { - $this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempGlobalPath); - - // Install dependencies and make sure the plugin runs. - $this->assertExecute( - 'composer global install -v --no-ansi', - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * Remove the dev dependency which caused the install of the plugin. - * This should also remove the plugin, but the plugin will still be loaded in memory, - * so we need to make sure it exits with 0. - */ - $this->assertExecute( - 'composer global remove --dev phpcs-composer-installer/multistandard -v --no-ansi', - 0, // Expected exit code. - $this->getUninstallStdOutExpectation(), // Expected stdout. - null, // No stderr expectation. - 'Uninstall of dev dependency did not meet expectations.' - ); - } - - /** - * Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS - * and the plugin when installed via require-dev by removing the dependency which installed it. - * - * @return void - */ - public function testRemovePHPCSViaDevUninstallLocal() - { - $this->writeComposerJsonFile($this->composerConfigRequireDev, static::$tempLocalPath); - - // Install dependencies and make sure the plugin runs. - $this->assertExecute( - sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * Remove the dev dependency which caused the install of the plugin. - * This should also remove the plugin, but the plugin will still be loaded in memory, - * so we need to make sure it exits with 0. - */ - $command = sprintf( - 'composer remove --dev phpcs-composer-installer/multistandard -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $this->assertExecute( - $command, - 0, // Expected exit code. - $this->getUninstallStdOutExpectation(), // Expected stdout. - null, // No stderr expectation. - 'Uninstall of dev dependency did not meet expectations.' - ); - } - - /** - * Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS - * and the plugin when installed via require by removing the dependency which installed it. - * - * @return void - */ - public function testRemovePHPCSViaNoDevUninstallGlobal() - { - $this->writeComposerJsonFile($this->composerConfigRequire, static::$tempGlobalPath); - - // Install dependencies and make sure the plugin runs. - $this->assertExecute( - 'composer global install -v --no-ansi', - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * Remove the dev dependency which caused the install of the plugin. - * This should also remove the plugin, but the plugin will still be loaded in memory, - * so we need to make sure it exits with 0. - */ - $this->assertExecute( - 'composer global remove phpcs-composer-installer/multistandard -v --no-ansi', - 0, // Expected exit code. - $this->getUninstallStdOutExpectation(), // Expected stdout. - null, // No stderr expectation. - 'Uninstall of no-dev dependency did not meet expectations.' - ); - } - - /** - * Test the plugin doesn't exit with a non-0 exit code and doesn't throw errors when removing PHPCS - * and the plugin when installed via require by removing the dependency which installed it. - * - * @return void - */ - public function testRemovePHPCSViaNoDevUninstallLocal() - { - $this->writeComposerJsonFile($this->composerConfigRequire, static::$tempLocalPath); - - // Install dependencies and make sure the plugin runs. - $this->assertExecute( - sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)), - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install dependencies.' - ); - - /* - * Remove the dev dependency which caused the install of the plugin. - * This should also remove the plugin, but the plugin will still be loaded in memory, - * so we need to make sure it exits with 0. - */ - $command = sprintf( - 'composer remove phpcs-composer-installer/multistandard -v --no-ansi --working-dir=%s', - escapeshellarg(static::$tempLocalPath) - ); - $this->assertExecute( - $command, - 0, // Expected exit code. - $this->getUninstallStdOutExpectation(), // Expected stdout. - null, // No stderr expectation. - 'Uninstall of no-dev dependency did not meet expectations.' - ); - } -} diff --git a/tests/IntegrationTest/RootPackageHandlingTest.php b/tests/IntegrationTest/RootPackageHandlingTest.php deleted file mode 100644 index 95bb419f..00000000 --- a/tests/IntegrationTest/RootPackageHandlingTest.php +++ /dev/null @@ -1,145 +0,0 @@ -createTestEnvironment(); - } - - /** - * Clean up. - */ - protected function tear_down() - { - $this->removeTestEnvironment(); - } - - /** - * Test that the plugin registers a standard found in the root package. - * - * @return void - */ - public function testSetInstalledPathsWhenRootPackageIsExternalStandard() - { - /* - * Copy one of the fixtures to the test directory. - */ - $this->recursiveDirectoryCopy(dirname(__DIR__) . '/fixtures/multistandard/', static::$tempLocalPath); - - // Install the dependencies, including the plugin. - $command = sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)); - $this->assertExecute( - $command, - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install the plugin.' - ); - - // Verify that the root package standard is registered correctly. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (first run)'); - - $this->assertSame( - 1, - preg_match('`installed_paths:\s+([^\n\r]+)\s+`', $result['stdout'], $matches), - 'Could not find the installed paths in the config' - ); - - // Work around differences in paths being returned between *nix and Windows. - $hasExpectedPath = false; - if ($matches[1] === '../../../') { // Most common. - $hasExpectedPath = true; - } else { - $needle = str_replace(sys_get_temp_dir(), '', static::$tempLocalPath); - if (substr_compare($matches[1], $needle, -\strlen($needle)) === 0) { - $hasExpectedPath = true; - } - } - - $this->assertTrue($hasExpectedPath, $matches[1], 'PHPCS configuration does not contain the root standard'); - } - - /** - * Test that the plugin does not act on root packages which aren't valid PHPCS external standards - * for the purposes of this plugin. - * - * @dataProvider dataInvalidRootPackages - * - * @param string $srcDir The path to the fixture to use as the root package. - * - * @return void - */ - public function testDontSetInstalledPathsForInvalidPackages($srcDir) - { - // Copy the fixture to the test directory. - $this->recursiveDirectoryCopy($srcDir, static::$tempLocalPath); - - // Install the dependencies, including the plugin. - $command = sprintf('composer install -v --no-ansi --working-dir=%s', escapeshellarg(static::$tempLocalPath)); - $this->assertExecute( - $command, - 0, // Expected exit code. - Plugin::MESSAGE_RUNNING_INSTALLER, // Expected stdout. - null, // No stderr expectation. - 'Failed to install the plugin.' - ); - - // Verify that the root package is not registered as a standard. - $result = $this->executeCliCommand('"vendor/bin/phpcs" --config-show', static::$tempLocalPath); - $this->assertSame(0, $result['exitcode'], 'Exitcode for "phpcs --config-show" did not match 0 (first run)'); - - // As the fixture doesn't contain other external standards, the installed_paths config should not exist. - $this->assertStringNotContainsString( - 'installed_paths:', - $result['stdout'], - 'Root package registered as an external standard with PHPCS, while it shouldn\'t be' - ); - } - - /** - * Data provider. - * - * @return array - */ - public function dataInvalidRootPackages() - { - return array( - 'Root package without ruleset file' => array( - 'srcDir' => dirname(__DIR__) . '/fixtures/no-ruleset/', - ), - 'Root package with incorrect type' => array( - 'srcDir' => dirname(__DIR__) . '/fixtures/incorrect-type/', - ), - ); - } -} diff --git a/tests/PHPCSVersions.php b/tests/PHPCSVersions.php deleted file mode 100644 index 7e64c72a..00000000 --- a/tests/PHPCSVersions.php +++ /dev/null @@ -1,435 +0,0 @@ - '2.0.0', - '2.1.0' => '2.1.0', - '2.2.0' => '2.2.0', - '2.3.0' => '2.3.0', - '2.3.1' => '2.3.1', - '2.3.2' => '2.3.2', - '2.3.3' => '2.3.3', - '2.3.4' => '2.3.4', - '2.4.0' => '2.4.0', - '2.5.0' => '2.5.0', - '2.5.1' => '2.5.1', - '2.6.0' => '2.6.0', - '2.6.1' => '2.6.1', - '2.6.2' => '2.6.2', - '2.7.0' => '2.7.0', - '2.7.1' => '2.7.1', - '2.8.0' => '2.8.0', - '2.8.1' => '2.8.1', - '2.9.0' => '2.9.0', - '2.9.1' => '2.9.1', - '2.9.2' => '2.9.2', - '3.1.0' => '3.1.0', - '3.1.1' => '3.1.1', - '3.2.0' => '3.2.0', - '3.2.1' => '3.2.1', - '3.2.2' => '3.2.2', - '3.2.3' => '3.2.3', - '3.3.0' => '3.3.0', - '3.3.1' => '3.3.1', - '3.3.2' => '3.3.2', - '3.4.0' => '3.4.0', - '3.4.1' => '3.4.1', - '3.4.2' => '3.4.2', - '3.5.0' => '3.5.0', - '3.5.1' => '3.5.1', - '3.5.2' => '3.5.2', - '3.5.3' => '3.5.3', - '3.5.4' => '3.5.4', - '3.5.5' => '3.5.5', - '3.5.6' => '3.5.6', - '3.5.7' => '3.5.7', - '3.5.8' => '3.5.8', - '3.6.0' => '3.6.0', - '3.6.1' => '3.6.1', - '3.6.2' => '3.6.2', - '3.7.0' => '3.7.0', - '3.7.1' => '3.7.1', - ); - - /** - * Retrieve an array with a specific number of PHPCS versions valid for the current PHP version. - * - * @param int $number Number of PHPCS versions to retrieve (excluding master/next major). - * Defaults to `0` = all supported versions for the current PHP version. - * When a non-0 value is passed, a random selection of versions supported - * by the current PHP version will be returned. - * @param bool $addMaster Whether or not `dev-master` should be added to the version array (providing - * it supports the current PHP version). - * Defaults to `false`. - * @param bool $addNextMajor Whether or not the development branch for the next PHPCS major should be - * added to the version array (providing it supports the current PHP version). - * Defaults to `false`. - * Note: if `true`, the version will be returned in a Composer usable format. - * - * @return array Numerically indexed array with PHPCS version identifiers as values. - */ - public static function get($number = 0, $addMaster = false, $addNextMajor = false) - { - if (is_int($number) === false || $number < 0) { - throw new RuntimeException('The number parameter must be a positive integer.'); - } - - $versions = self::getSupportedVersions(); - - $selection = array_values($versions); - if ($number !== 0 && empty($versions) === false) { - $number = min($number, count($versions)); - $selection = (array) array_rand($versions, $number); - } - - if ($addMaster === true) { - $selection[] = self::MASTER; - } - - if ($addNextMajor === true && self::isNextMajorSupported()) { - $selection[] = self::NEXT_MAJOR; - } - - return $selection; - } - - /** - * Retrieve an array of the highest and lowest PHPCS versions valid for the current PHP version. - * - * @param bool $addMaster Whether or not `dev-master` should be added to the version array (providing - * it supports the current PHP version). - * Defaults to `false`. - * @param bool $addNextMajor Whether or not the development branch for the next PHPCS major should be - * added to the version array (providing it supports the current PHP version). - * Defaults to `false`. - * Note: if `true`, the version will be returned in a Composer usable format. - * - * @return array Numerically indexed array with PHPCS version identifiers as values. - */ - public static function getHighLow($addMaster = false, $addNextMajor = false) - { - $versions = self::getSupportedVersions(); - $selection = array(); - - if (empty($versions) === false) { - $selection[] = min($versions); - $selection[] = max($versions); - } - - if ($addMaster === true) { - $selection[] = self::MASTER; - } - - if ($addNextMajor === true && self::isNextMajorSupported()) { - $selection[] = self::NEXT_MAJOR; - } - - return $selection; - } - - /** - * Retrieve an array of the highest and lowest supported PHPCS versions for each PHPCS major - * (valid for the current PHP version). - * - * @param bool $addMaster Whether or not `dev-master` should be added to the version array (providing - * it supports the current PHP version). - * Defaults to `false`. - * @param bool $addNextMajor Whether or not the development branch for the next PHPCS major should be - * added to the version array (providing it supports the current PHP version). - * Defaults to `false`. - * Note: if `true`, the version will be returned in a Composer usable format. - * - * @return array Numerically indexed array with PHPCS version identifiers as values. - */ - public static function getHighLowEachMajor($addMaster = false, $addNextMajor = false) - { - $versions = self::getSupportedVersions(); - $versions2 = array(); - $versions3 = array(); - - if (empty($versions) === false) { - $versions2 = array_filter( - $versions, - function ($v) { - return $v[0] === '2'; - } - ); - $versions3 = array_filter( - $versions, - function ($v) { - return $v[0] === '3'; - } - ); - } - - $selection = array(); - if (empty($versions2) === false) { - $selection[] = min($versions2); - $selection[] = max($versions2); - } - - if (empty($versions3) === false) { - $selection[] = min($versions3); - $selection[] = max($versions3); - } - - if ($addMaster === true) { - $selection[] = self::MASTER; - } - - if ($addNextMajor === true && self::isNextMajorSupported()) { - $selection[] = self::NEXT_MAJOR; - } - - return $selection; - } - - /** - * Get a random PHPCS version which is valid for the current PHP version. - * - * @param bool $inclMaster Whether or not `dev-master` should be included in the array to pick - * the version from (providing it supports the current PHP version). - * Defaults to `false`. - * @param bool $inclNextMajor Whether or not the development branch for the next PHPCS major should be included - * in the array to pick the version (providing it supports the current PHP version). - * Defaults to `false`. - * Note: if `true`, the version will be returned in a Composer usable format. - * - * @return string - */ - public static function getRandom($inclMaster = false, $inclNextMajor = false) - { - $versions = self::getSupportedVersions(); - - if ($inclMaster === true) { - $versions[self::MASTER] = self::MASTER; - } - - if ($inclNextMajor === true && self::isNextMajorSupported()) { - $versions[self::NEXT_MAJOR] = self::NEXT_MAJOR; - } - - return array_rand($versions); - } - - /** - * Convert a versions array to an array suitable for use as a PHPUnit dataprovider. - * - * @param array $versions Array with PHPCS version numbers as values. - * - * @return array Array of PHPCS version identifiers in a format usable for a test data provider. - */ - public static function toDataprovider($versions) - { - if (is_array($versions) === false || $versions === array()) { - throw new RuntimeException('The versions parameter must be a non-empty array.'); - } - - $data = array(); - foreach ($versions as $version) { - $data['phpcs ' . $version] = array( - 'phpcsVersion' => $version, - ); - } - - return $data; - } - - /** - * Retrieve an array with PHPCS versions valid for the current PHP version. - * - * @return array Array with PHPCS version identifiers as both keys and values. - */ - public static function getSupportedVersions() - { - /* - * Adjust the list of available versions based on the PHP version on which the tests are run. - */ - switch (\CLI_PHP_MINOR) { - case '5.3': - $versions = array_filter( - self::$allPhpcsVersions, - function ($version) { - // PHPCS 2.9.2 is the highest version still supporting PHP 5.3. - return version_compare($version, '2.9.2', '<='); - } - ); - break; - - case '7.2': - $versions = array_filter( - self::$allPhpcsVersions, - function ($version) { - // PHPCS 2.9.2 is the first PHPCS version with runtime support for PHP 7.2. - return version_compare($version, '2.9.2', '>='); - } - ); - break; - - case '7.3': - $versions = array_filter( - self::$allPhpcsVersions, - function ($version) { - // PHPCS 3.3.1 is the first PHPCS version with runtime support for PHP 7.3. - return version_compare($version, '3.3.1', '>='); - } - ); - break; - - case '7.4': - $versions = array_filter( - self::$allPhpcsVersions, - function ($version) { - // PHPCS 3.5.0 is the first PHPCS version with runtime support for PHP 7.4. - return version_compare($version, '3.5.0', '>='); - } - ); - break; - - case '8.0': - $versions = array_filter( - self::$allPhpcsVersions, - function ($version) { - // PHPCS 3.5.7 is the first PHPCS version with runtime support for PHP 8.0. - return version_compare($version, '3.5.7', '>='); - } - ); - break; - - case '8.1': - $versions = array_filter( - self::$allPhpcsVersions, - function ($version) { - // PHPCS 3.6.1 is the first PHPCS version with runtime support for PHP 8.1. - return version_compare($version, '3.6.1', '>='); - } - ); - break; - - case '8.2': - $versions = array_filter( - self::$allPhpcsVersions, - function ($version) { - // PHPCS 3.6.1 is the first PHPCS version with runtime support for PHP 8.2. - return version_compare($version, '3.6.1', '>='); - } - ); - break; - - case '8.3': - /* - * At this point in time, it is unclear as of which PHPCS version PHP 8.2 will be supported. - * In other words: tests should only use dev-master/4.x when on PHP 8.2 for the time being. - */ - $versions = array(); - break; - - default: - $versions = self::$allPhpcsVersions; - break; - } - - return $versions; - } - - /** - * Determine if the current PHP version is supported on the "next major" branch of PHPCS. - * - * @return bool - */ - public static function isNextMajorSupported() - { - return version_compare(\CLI_PHP_MINOR, '7.2', '>='); - } - - /** - * Retrieve an array of the PHPCS native standards which are included in a particular PHPCS version. - * - * @param string $version PHPCS version number. - * - * @return array Numerically indexed array of standards, natural sort applied. - */ - public static function getStandards($version) - { - if ( - is_string($version) === false - || (isset(self::$allPhpcsVersions[$version]) === false - && $version !== self::MASTER - && $version !== self::NEXT_MAJOR) - ) { - throw new RuntimeException('The version parameter must be a valid PHPCS version number as a string.'); - } - - $standards = array( - 'PEAR', - 'PSR1', - 'PSR2', - 'Squiz', - 'Zend', - ); - - if ($version !== self::NEXT_MAJOR) { - // The MySource standard is available in PHPCS 2.x and 3.x, but will be removed in 4.0. - $standards[] = 'MySource'; - } - - if ( - $version !== self::MASTER - && $version !== self::NEXT_MAJOR - && version_compare($version, '3.0.0', '<') - ) { - // The PHPCS standard was available in PHPCS 2.x, but has been removed in 3.0. - $standards[] = 'PHPCS'; - } - - if ( - $version === self::MASTER - || $version === self::NEXT_MAJOR - || version_compare($version, '3.3.0', '>=') - ) { - // The PSR12 standard is available since PHPCS 3.3.0. - $standards[] = 'PSR12'; - } - - sort($standards, \SORT_NATURAL); - - return $standards; - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php deleted file mode 100644 index a4773111..00000000 --- a/tests/TestCase.php +++ /dev/null @@ -1,684 +0,0 @@ - 'local', - 'tempGlobalPath' => 'global', - ); - - foreach ($subDirs as $property => $subDir) { - $path = static::$tempDir . '/' . $subDir; - if (mkdir($path, 0766, true) === false || is_dir($path) === false) { - throw new RuntimeException("Failed to create the $path directory for the test"); - } - - static::${$property} = $path; - } - - putenv('COMPOSER_HOME=' . static::$tempGlobalPath); - } - - public static function removeTestEnvironment() - { - if (file_exists(static::$tempDir) === true) { - // Remove temp directory, including all files. - if (static::onWindows() === true) { - // Windows. - exec(sprintf('rd /s /q %s', escapeshellarg(static::$tempDir)), $output, $exitCode); - } else { - exec(sprintf('rm -rf %s', escapeshellarg(static::$tempDir)), $output, $exitCode); - } - - if ($exitCode !== 0) { - throw new RuntimeException( - 'Failed to remove the temp directory created for the test: ' . \PHP_EOL . 'Error: ' . $output - ); - } - - clearstatcache(); - } - - putenv('COMPOSER_HOME'); - } - - - /* ***** CUSTOM ASSERTIONS ***** */ - - /** - * Assert that a composer.json file is valid for use in the tests. - * - * @param string $workingDir The working directory in which to execute the command. - * @param string $file The file to execute the command on. - * By default the command will execute on the `composer.json` file - * in the current or working directory. - * - * @return void - * - * @throws RuntimeException When either passed argument is not a string. - * @throws RuntimeException When both arguments are passed as Composer can only handle one. - */ - public function assertComposerValidates($workingDir = '', $file = '') - { - if (is_string($workingDir) === false) { - throw new RuntimeException('Working directory must be a string.'); - } - - if (is_string($file) === false) { - throw new RuntimeException('File must be a string.'); - } - - if ($workingDir !== '' && $file !== '') { - throw new RuntimeException( - 'Pass either the working directory OR a file name. Composer does not handle both in the same command.' - ); - } - - $command = 'composer validate --no-check-all --no-check-publish --no-check-lock --no-ansi'; - $stderr = '%s is valid'; - $message = 'Provided Composer configuration is not valid.'; - - if ($workingDir !== '') { - $command .= sprintf(' --working-dir=%s', escapeshellarg($workingDir)); - $stderr = sprintf($stderr, 'composer.json'); - $message .= ' Working directory: ' . $workingDir; - } - - if ($file !== '') { - $command .= ' ' . escapeshellarg($file); - $stderr = sprintf($stderr, $file); - $message .= ' File: ' . $file; - } - - $this->assertExecute( - $command, - 0, // Expected exit code. - null, // Expected stdout. - $stderr, // Expected stderr. - $message - ); - } - - /** - * Assert that a command when executed meets certain expectations for exit code and output. - * - * Note: the stdout and stderr assertions will verify that the passed expectation is a **substring** - * of the actual output using `assertStringContainsString()`. - * - * The stdout and stderr assertions will disregard potential color codes in the actual output - * when no color codes are included in the expectation. - * - * If more specific assertions are needed, use the `TestCase::executeCliCommand()` directly and - * apply assertions to the results from that function call. - * - * @param string $command The CLI command to execute. - * @param int|null $expectedExitCode Optional. The expected exit code for the command. - * @param string|null $expectedStdOut Optional. The expected command output to stdout. - * @param string|null $expectedStdErr Optional. The expected command output to stderr. - * @param string $message Optional. Message to display when an assertion fails. - * @param string|null $workingDir Optional. The directory in which to execute the command. - * Defaults to `null` = the working directory of the current PHP process. - * Note: if the command itself already contains a "working directory" argument, - * this parameter will normally not need to be passed. - * - * @return void - * - * @throws RuntimeException When neither $expectedExitCode, $expectedStdOut or $expectedStdErr are passed. - */ - public function assertExecute( - $command, - $expectedExitCode = null, - $expectedStdOut = null, - $expectedStdErr = null, - $message = '', - $workingDir = null - ) { - if ($expectedExitCode === null && $expectedStdOut === null && $expectedStdErr === null) { - throw new RuntimeException('At least one expectation has to be set for the executed command.'); - } - - $result = $this->executeCliCommand($command, $workingDir); - - if (is_string($expectedStdOut)) { - $msg = 'stdOut did not contain the expected output. ' . $message; - - if ($expectedStdOut === '') { - $this->assertSame($expectedStdOut, $result['stdout'], $msg); - } else { - $stdout = $this->maybeStripColors($expectedStdOut, $result['stdout']); - $this->assertStringContainsString($expectedStdOut, $stdout, $msg); - } - } - - if (is_string($expectedStdErr)) { - $msg = 'stdErr did not contain the expected output. ' . $message; - - if ($expectedStdErr === '') { - $this->assertSame($expectedStdErr, $result['stderr'], $msg); - } else { - $stderr = $this->maybeStripColors($expectedStdErr, $result['stderr']); - $this->assertStringContainsString($expectedStdErr, $stderr, $msg); - } - } - - if (is_int($expectedExitCode)) { - $msg = 'Exit code did not match expected code. ' . $message; - $this->assertSame($expectedExitCode, $result['exitcode'], $msg); - } - } - - - /* ***** HELPER METHODS ***** */ - - /** - * Determine whether or not the tests are being run on Windows. - * - * @return bool - */ - protected static function onWindows() - { - return stripos(\PHP_OS, 'WIN') === 0; - } - - /** - * Create a composer.json file based on a given configuration. - * - * @param array $config Composer configuration as an array. - * @param string $directory Location to write the resulting `composer.json` file to (without trailing slash). - * - * @return void - * - * @throws RuntimeException When either of the passed parameters are of the wrong data type. - * @throws RuntimeException When the provided configuration is invalid. - * @throws RuntimeException When the configuration could not be written to a file. - */ - protected static function writeComposerJsonFile($config, $directory) - { - if (is_array($config) === false || $config === array()) { - throw new RuntimeException('Configuration must be a non-empty array.'); - } - - if (is_string($directory) === false || $directory === '') { - throw new RuntimeException('Directory must be a non-empty string.'); - } - - // Inject artifact for this plugin and some dummy standards. - if (isset($config['repositories']) === false) { - $config['repositories'][] = array( - 'type' => 'artifact', - 'url' => \ZIP_ARTIFACT_DIR, - ); - } - - // Inject ability to run the plugin via a script. - if (isset($config['scripts']['install-codestandards']) === false) { - $config['scripts']['install-codestandards'] = array( - 'PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run', - ); - } - - // Inject permission for this plugin to run (Composer 2.2 compat). - if (isset($config['config']['allow-plugins']['dealerdirect/phpcodesniffer-composer-installer']) === false) { - $config['config']['allow-plugins']['dealerdirect/phpcodesniffer-composer-installer'] = true; - } - - /* - * Disable TLS when on Windows with Composer 1.x and PHP 5.4. - * @link https://github.com/composer/composer/issues/10495 - */ - if (static::onWindows() === true && \CLI_PHP_MINOR === '5.4' && strpos(\COMPOSER_VERSION, '1') === 0) { - $config['config']['disable-tls'] = true; - } - - $encoded = json_encode($config, \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT); - if (json_last_error() !== \JSON_ERROR_NONE || $encoded === false) { - throw new RuntimeException('Provided configuration can not be encoded to valid JSON'); - } - - $written = file_put_contents($directory . '/composer.json', $encoded); - - if ($written === false) { - throw new RuntimeException('Failed to create the composer.json file in the temp directory for the test'); - } - - // Add debug information to the test listener which will be displayed in case the test fails. - DebugTestListener::debugLog( - '---------------------------------------' . \PHP_EOL - . 'composer.json: ' . \PHP_EOL - . $encoded . \PHP_EOL - . '---------------------------------------' . \PHP_EOL - ); - } - - /** - * Helper function for CLI commands. - * - * This function stabilizes the CLI command for the purpose of these tests when the - * tests are run in a non-isolated environment with multiple installed PHP versions - * and multiple installed Composer versions. - * - * This prevents the system default PHP version being used instead of the PHP version - * which was used to initiate the test run. - * Similarly, this prevents the system default Composer version being used instead of the - * target Composer version for this test run. - * - * @param string $command The command to stabilize. - * @param string|null $workingDir Optional. The directory in which the command will be executed. - * Defaults to `null` = the working directory of the current PHP process. - * - * @return string - * - * @throws RuntimeException When the passed command is not a string. - */ - protected static function stabilizeCommand($command, $workingDir = null) - { - if (is_string($command) === false) { - throw new RuntimeException('Command must be a string.'); - } - - if (strpos($command, 'vendor/bin/phpcs') !== false) { - $phpcsCommand = static::getPhpcsCommand($workingDir); - if (strpos($command, 'vendor/bin/phpcs') === 0) { - $command = '"' . \PHP_BINARY . '" ' . $phpcsCommand . substr($command, 16); - } - - if (strpos($command, '"vendor/bin/phpcs"') === 0) { - $command = '"' . \PHP_BINARY . '" ' . $phpcsCommand . substr($command, 18); - } - - if (strpos($command, ' vendor/bin/phpcs ') !== false) { - $command = str_replace(' vendor/bin/phpcs ', ' ' . $phpcsCommand . ' ', $command); - } - - if (strpos($command, ' "vendor/bin/phpcs" ') !== false) { - $command = str_replace(' "vendor/bin/phpcs" ', ' ' . $phpcsCommand . ' ', $command); - } - } - - if (strpos($command, 'php composer.phar ') !== false) { - $command = str_replace('php composer.phar ', '"' . \PHP_BINARY . '" "' . \COMPOSER_PHAR . '" ', $command); - } - - if (strpos($command, 'php ') === 0) { - $command = '"' . \PHP_BINARY . '" ' . substr($command, 3); - } - - if (strpos($command, ' php ') !== false) { - $command = str_replace(' php ', ' "' . \PHP_BINARY . '" ', $command); - } - - if (strpos($command, 'composer ') !== false) { - $command = str_replace('composer ', '"' . \PHP_BINARY . '" "' . \COMPOSER_PHAR . '" ', $command); - } - - // Make sure the `--no-interaction` flag is set for all Composer commands to prevent tests hanging. - if (strpos($command, '"' . \COMPOSER_PHAR . '"') !== false && strpos($command, ' --no-interaction') === false) { - $command = str_replace('"' . \COMPOSER_PHAR . '"', '"' . \COMPOSER_PHAR . '" --no-interaction', $command); - } - - /* - * If the command will be run on Windows in combination with PHP < 8.0, wrap it in an extra set of quotes. - * Note: it is unclear what changes in PHP 8.0, but the quotes will now suddenly break things. - * Ref: https://www.php.net/manual/en/function.proc-open.php#example-3331 - */ - if (static::onWindows() === true && substr(\CLI_PHP_MINOR, 0, 1) < 8) { - $command = '"' . $command . '"'; - } - - return $command; - } - - /** - * Retrieve the command to use to run PHPCS. - * - * @param string|null $workingDir Optional. The directory in which the command will be executed. - * Defaults to `null` = the working directory of the current PHP process. - * - * @return string - */ - protected static function getPhpcsCommand($workingDir = null) - { - $command = '"vendor/squizlabs/php_codesniffer/bin/phpcs"'; // PHPCS 3.x. - - if (is_string($workingDir) && file_exists($workingDir . '/vendor/squizlabs/php_codesniffer/scripts/phpcs')) { - // PHPCS 2.x. - $command = '"vendor/squizlabs/php_codesniffer/scripts/phpcs"'; - } - - return $command; - } - - /** - * Helper function to execute a CLI command. - * - * @param string $command The CLI command to execute. - * @param string|null $workingDir Optional. The directory in which to execute the command. - * Defaults to `null` = the working directory of the current PHP process. - * Note: if the command itself already contains a "working directory" argument, - * this parameter will normally not need to be passed. - * @param bool $autoRetry Internal. Whether the command should be retried if it fails on a particular - * Composer exception. This parameter should only be set by the method itself - * when recursing on itself. - * - * @return array Format: - * 'exitcode' int The exit code from the command. - * 'stdout' string The output send to stdout. - * 'stderr' string The output send to stderr. - * - * @throws RuntimeException When the passed arguments do not comply. - * @throws RuntimeException When no resource could be obtained to execute the command. - */ - public static function executeCliCommand($command, $workingDir = null, $autoRetry = true) - { - if (is_string($command) === false || $command === '') { - throw new RuntimeException('Command must be a non-empty string.'); - } - - if (is_null($workingDir) === false && (is_string($workingDir) === false || $workingDir === '')) { - throw new RuntimeException('Working directory must be a non-empty string or null.'); - } - - $command = static::stabilizeCommand($command, $workingDir); - $descriptorspec = array( - 0 => array("pipe", "r"), // stdin - 1 => array("pipe", "w"), // stdout - 2 => array("pipe", "w"), // stderr - ); - - $process = proc_open($command, $descriptorspec, $pipes, $workingDir); - - if (is_resource($process) === false) { - throw new RuntimeException('Could not obtain a resource with proc_open() to execute the command.'); - } - - $result = array(); - fclose($pipes[0]); - - $result['stdout'] = stream_get_contents($pipes[1]); - fclose($pipes[1]); - - $result['stderr'] = stream_get_contents($pipes[2]); - fclose($pipes[2]); - - $result['exitcode'] = proc_close($process); - - // Add debug information to the test listener which will be displayed in case the test fails. - DebugTestListener::debugLog( - '---------------------------------------' . \PHP_EOL - . 'Command: ' . $command . \PHP_EOL - . 'Output: ' . var_export($result, true) . \PHP_EOL - . '---------------------------------------' . \PHP_EOL - ); - - /* - * Prevent the complete CI run failing on a particular error which Composer sometimes - * runs into. Retry the command instead. In most cases, that should fix it. - * If the command still fails, just return the results. - */ - if ( - $autoRetry === true - && $result['exitcode'] === 1 - && strpos($command, '"' . \COMPOSER_PHAR . '"') !== false - && strpos($result['stderr'], '[Composer\\Downloader\\TransportException]') !== false - && strpos($result['stderr'], 'Peer fingerprint did not match') !== false - ) { - // Retry and return the results of the retry. - return self::executeCliCommand($command, $workingDir, false); - } - - return $result; - } - - /** - * Helper function which strips potential CLI colour codes from the actual output - * when the expected output does not contain any colour codes. - * - * @param string $expected Expected output. - * @param string $actual Actual output. - * - * @return string Actual output, potentially stripped of colour codes. - * - * @throws RuntimeException When either passed argument is not a string. - */ - protected function maybeStripColors($expected, $actual) - { - if (is_string($expected) === false) { - throw new RuntimeException('Expected output must be a string.'); - } - - if (is_string($actual) === false) { - throw new RuntimeException('Actual output must be a string.'); - } - - if ($expected === '') { - // Nothing to do. - return $actual; - } - - if ( - (strpos($expected, "\033") === false && strpos($actual, "\033") !== false) - || (strpos($expected, "\x1b") === false && strpos($actual, "\x1b") !== false) - ) { - $actual = preg_replace('`(?:\\\\033|\\\\x1b)\\\\[[0-9]+(;[0-9]*)[A-Za-z]`', '', $actual); - } - - return $actual; - } - - /** - * Helper function to create a file which can be used to run PHPCS against. - * - * @param string $path The full path, including filename, to write the file to. - * @param string $contents Optional. The ccntents for the file. - * Defaults to a simple `echo 'Hello world';` PHP file. - * - * @return void - * - * @throws RuntimeException When either passed argument is not a string. - * @throws RuntimeException When the file could not be created. - */ - protected function createFile($path, $contents = '') - { - if (is_string($path) === false || $path === '') { - throw new RuntimeException('Path must be a non-empty string.'); - } - - if (is_string($contents) === false) { - throw new RuntimeException('Contents must be a string.'); - } - - if ($contents === '') { - $contents = <<<'PHP' - $fileInfo) { - $subPath = $iterator->getSubPathname(); - - // Special case the Composer config. - if ($subPath === 'composer.json') { - $composerConfig = json_decode(file_get_contents($fileInfo->getPathname()), true); - $this->writeComposerJsonFile($composerConfig, $destDir); - continue; - } - - $target = $destDir . '/' . $subPath; - - if ($fileInfo->isDir()) { - if (mkdir($target, 0766, true) === false || is_dir($target) === false) { - throw new RuntimeException("Failed to create the $target directory for the test"); - } - continue; - } - - if ($fileInfo->isFile()) { - if (copy($fileInfo->getPathname(), $target) === false || is_file($target) === false) { - throw new RuntimeException("Failed to copy $src to $target "); - } - } - } - } - - /** - * Retrieve a list of the standards recognized by PHPCS based on the output of `phpcs -i`. - * - * @param string $phrase The output of `phpcs -i`. - * - * @return array Numerically indexed array of standards, natural sort applied. - * - * @throws RuntimeException When the passed argument is not a string. - * @throws RuntimeException When the output could not be parsed. - */ - protected function standardsPhraseToArray($phrase) - { - if (is_string($phrase) === false) { - throw new RuntimeException('The input phrase must be a string.'); - } - - $phrase = trim($phrase); - - if ($phrase === 'No coding standards are installed.') { - return array(); - } - - if (strpos($phrase, 'The only coding standard installed is ') === 0) { - $standard = str_replace('The only coding standard installed is ', '', $phrase); - return (array) trim($standard); - } - - $phrase = str_replace('The installed coding standards are ', '', $phrase); - $parts = explode(' and ', $phrase); - - if (count($parts) !== 2) { - throw new RuntimeException( - 'Looks like the output from PHPCS for phpcs -i has changed.' - . ' Please update the `TestCase::standardsPhraseToArray()` method.' - . ' Input phrase: ' . $phrase - ); - } - - $standards = explode(', ', $parts[0]); - $standards[] = $parts[1]; - $standards = array_map('trim', $standards); // Trim off whitespace just to be on the safe side. - - sort($standards, \SORT_NATURAL); - - return $standards; - } - - /** - * Retrieve a list of the paths registered with PHPCS based on the output of `phpcs --config-show`. - * - * @param string $configShow The `stdout` output of `phpcs --config-show`. - * - * @return array Numerically indexed array of paths, stripped of absolute/relative path differences, - * natural sort applied. - * - * @throws RuntimeException When the passed argument is not a string. - */ - protected function configShowToPathsArray($configShow) - { - if (is_string($configShow) === false) { - throw new RuntimeException('The config-show input must be a string.'); - } - - if (preg_match('`installed_paths:\s+([^\n\r]+)\s+`', $configShow, $matches) !== 1) { - return array(); - } - - $pathsAsArray = explode(',', $matches[1]); - $pathsAsArray = array_map( - function ($value) { - $search = array( - '`^[^\r\n]+/vendor/`', - '`^\.\./\.\./`', - ); - - $replaced = preg_replace($search, '/', $value); - if ($replaced === null) { - return $value; - } - - return trim($replaced); // Trim off whitespace just to be on the safe side. - }, - $pathsAsArray - ); - - sort($pathsAsArray, \SORT_NATURAL); - - return $pathsAsArray; - } -} diff --git a/tests/artifact/.gitkeep b/tests/artifact/.gitkeep deleted file mode 100644 index d06031b9..00000000 --- a/tests/artifact/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -# This directory has to exist to allow artifact files to be written to it. \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index f18de6c0..00000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,122 +0,0 @@ -clearOldArtifacts(); - $zipCreator->createPluginArtifact(dirname(__DIR__), \PLUGIN_ARTIFACT_VERSION); - $zipCreator->createFixtureArtifacts(__DIR__ . '/fixtures/'); - unset($zipCreator); -} else { - echo 'Please enable the zip extension before running the tests.'; - die(1); -} - -/* - * Set a few constants for use throughout the tests. - */ - -define('CLI_PHP_MINOR', substr(\PHP_VERSION, 0, strpos(\PHP_VERSION, '.', 2))); - -if (\getenv('COMPOSER_PHAR') !== false) { - define('COMPOSER_PHAR', getenv('COMPOSER_PHAR')); -} elseif (strpos(strtoupper(\PHP_OS), 'WIN') === 0) { - // Windows. - exec('where composer.phar', $output, $exitcode); - if ($exitcode === 0 && empty($output) === false) { - define('COMPOSER_PHAR', trim(implode('', $output))); - } -} else { - exec('which composer.phar', $output, $exitcode); - if ($exitcode === 0 && empty($output) === false) { - define('COMPOSER_PHAR', trim(implode('', $output))); - } -} - -if (defined('COMPOSER_PHAR') === false) { - echo 'Please add a configuration to your local phpunit.xml' - . ' overload file before running the tests.' . \PHP_EOL - . 'The value should point to the local Composer phar file you want to use for the tests.'; - die(1); -} - -// Get the version of Composer being used. -$command = '"' . \PHP_BINARY . '" "' . \COMPOSER_PHAR . '" --version --no-ansi --no-interaction'; -$lastLine = exec($command, $output, $exitcode); -if ($exitcode === 0 && preg_match('`Composer (?:version )?([^\s]+)`', $lastLine, $matches) === 1) { - define('COMPOSER_VERSION', $matches[1]); -} else { - echo 'Could not determine the version of Composer being used.'; - die(1); -} diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md deleted file mode 100644 index e6aed235..00000000 --- a/tests/fixtures/README.md +++ /dev/null @@ -1,90 +0,0 @@ -# Test fixtures - -The subdirectories in this folder contain "fake" PHPCS standards. - -As more and more external PHPCS standards include a `require` for this plugin, these test fixtures should be used in the integration tests instead of _real_ PHPCS standards. - -Using these fixtures will make creating tests more straight-forward as: -* It should prevent issues with the plugin version as used in the tests (version of the created zip artifact) not matching the version constraint for the plugin in a _real_ standard, which would result in Composer downloading from Packagist instead of using the artifact package created for use in the tests. -* It means we don't need to keep track of the version history of external standards in regards to: - - whether or not the external standard uses the correct project `type` in their `composer.json`. - - whether or not they `require` the plugin. - - whether or not they comply with the PHPCS naming conventions. - - whether or not the standard is compatible with PHPCS 2.x/3.x/4.x. - - etc... - -Each subdirectory in this `fixtures` directory will be zipped up and placed in the `artifact` subdirectory ahead of running the tests, making them available to all tests. - -The artifact version of each fake standard will always be `1.0.0`, unless otherwise indicated. -Setting a different version for a fake standard can be achieved by explicitly setting the `version` in the `composer.json` file of the fake standard. - -Any particular test can use one or more of these fake standards. - -Notes: -* The "fake" standards DO need to comply with the naming conventions from PHPCS, which means that the name of a standard as set in the `ruleset.xml` file MUST be the same as the name of the directory containing the `ruleset.xml` file. - So the `ruleset.xml` file for a standard called `Dummy` MUST be in a (sub)directory named `Dummy`. -* A "fake" standard will normally consist of a `composer.json` file in the fake project root and one or more `ruleset.xml` files. -* If the "fake" standard `require`s the plugin, it should do so with `'*'` as the version constraint. -* The "fake" standards generally do NOT need to contain any sniffs or actual rules in the ruleset (unless the standard will be used in a test for running PHPCS). - -It is recommended to add a short description of the situation which can be tested with each fixture to the below list. - -## Valid packages - -### Package name: `phpcs-composer-installer/dummy-subdir` - -**Description:** -An external PHPCS standard with the `ruleset.xml` file in a subdirectory ("normal" standard setup). - -| Characteristics | Notes | -|--------------------------|--------------------------------------------------------------------------------------------------| -| **Standard(s):** | `DummySubDir` | -| **Includes sniff(s):** | :heavy_checkmark: One sniff - `DummySubDir.Demo.Demo` - which is PHPCS cross-version compatible. | -| **Requires the plugin:** | :x: | - -### Package name: `phpcs-composer-installer/multistandard` - -**Description:** -An external PHPCS standard with multiple rulesets, each in a subdirectory ("normal" standard setup). - -| Characteristics | Notes | -|--------------------------|------------------------------------------------------------| -| **Standard(s):** | `MyFirstStandard`, `MySecondStandard`, `My-Third-Standard` | -| **Includes sniff(s):** | :x: | -| **Requires the plugin:** | :heavy_checkmark: | - -### Package name: `phpcs-composer-installer/dummy-src` - -**Description:** -An external PHPCS standard with the `ruleset.xml` file in a deeper nested subdirectory. - -| Characteristics | Notes | -|--------------------------|-------------------| -| **Standard(s):** | `DummySrcSubDir` | -| **Includes sniff(s):** | :x: | -| **Requires the plugin:** | :heavy_checkmark: | - - -## Invalid packages - -**_These packages should not be installed by the plugin._** - -### Package name: `phpcs-composer-installer/no-ruleset` - -**Description:** -A Composer package which has the `phpcodesniffer-standard` type set in the `composer.json` file, but doesn't contain a `ruleset.xml` file (but does contain a `ruleset.xml.dist` file, which is not a file recognized by PHPCS). - -| Characteristics | Notes | -|--------------------------|-------------------| -| **Standard(s):** | `NoRuleset` | -| **Requires the plugin:** | :heavy_checkmark: | - -### Package name: `phpcs-composer-installer/incorrect-type` - -**Description:** -An external PHPCS standard which does not have the `phpcodesniffer-standard` type set in the `composer.json` file. - -| Characteristics | Notes | -|--------------------------|-------------------| -| **Standard(s):** | `IncorrectType` | -| **Requires the plugin:** | :heavy_checkmark: | diff --git a/tests/fixtures/dummy-src/composer.json b/tests/fixtures/dummy-src/composer.json deleted file mode 100644 index 9ded9e25..00000000 --- a/tests/fixtures/dummy-src/composer.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name" : "phpcs-composer-installer/dummy-src", - "description" : "Dummy PHPCS standard with deeper nested subdirectory ruleset for use in the tests.", - "type" : "phpcodesniffer-standard", - "license" : "MIT", - "require" : { - "php" : ">=5.4", - "squizlabs/php_codesniffer" : "*", - "dealerdirect/phpcodesniffer-composer-installer" : "*" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} diff --git a/tests/fixtures/dummy-src/src/DummySrcSubDir/ruleset.xml b/tests/fixtures/dummy-src/src/DummySrcSubDir/ruleset.xml deleted file mode 100644 index 3e434f11..00000000 --- a/tests/fixtures/dummy-src/src/DummySrcSubDir/ruleset.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Dummy PHPCS standard for testing. - diff --git a/tests/fixtures/dummy-subdir/DummySubDir/Sniffs/Demo/DemoSniff.php b/tests/fixtures/dummy-subdir/DummySubDir/Sniffs/Demo/DemoSniff.php deleted file mode 100644 index f18b7583..00000000 --- a/tests/fixtures/dummy-subdir/DummySubDir/Sniffs/Demo/DemoSniff.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - Dummy PHPCS standard for testing. - diff --git a/tests/fixtures/dummy-subdir/composer.json b/tests/fixtures/dummy-subdir/composer.json deleted file mode 100644 index 8d082365..00000000 --- a/tests/fixtures/dummy-subdir/composer.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name" : "phpcs-composer-installer/dummy-subdir", - "description" : "Dummy PHPCS standard with subdirectory ruleset for use in the tests.", - "type" : "phpcodesniffer-standard", - "license" : "MIT", - "require" : { - "php" : ">=5.4", - "squizlabs/php_codesniffer" : "*" - } -} diff --git a/tests/fixtures/incorrect-type/IncorrectType/ruleset.xml b/tests/fixtures/incorrect-type/IncorrectType/ruleset.xml deleted file mode 100644 index 3e889097..00000000 --- a/tests/fixtures/incorrect-type/IncorrectType/ruleset.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Dummy PHPCS standard for testing. - diff --git a/tests/fixtures/incorrect-type/composer.json b/tests/fixtures/incorrect-type/composer.json deleted file mode 100644 index cbc76e3c..00000000 --- a/tests/fixtures/incorrect-type/composer.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name" : "phpcs-composer-installer/incorrect-type", - "description" : "Dummy PHPCS standard with subdirectory ruleset for use in the tests.", - "type" : "coding-standard", - "license" : "MIT", - "require" : { - "php" : ">=5.4", - "squizlabs/php_codesniffer" : "*", - "dealerdirect/phpcodesniffer-composer-installer" : "*" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} diff --git a/tests/fixtures/multistandard/My-Third-Standard/ruleset.xml b/tests/fixtures/multistandard/My-Third-Standard/ruleset.xml deleted file mode 100644 index ca6a9818..00000000 --- a/tests/fixtures/multistandard/My-Third-Standard/ruleset.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Dummy PHPCS standard for testing. - diff --git a/tests/fixtures/multistandard/MyFirstStandard/ruleset.xml b/tests/fixtures/multistandard/MyFirstStandard/ruleset.xml deleted file mode 100644 index 424ac051..00000000 --- a/tests/fixtures/multistandard/MyFirstStandard/ruleset.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Dummy PHPCS standard for testing. - diff --git a/tests/fixtures/multistandard/MySecondStandard/ruleset.xml b/tests/fixtures/multistandard/MySecondStandard/ruleset.xml deleted file mode 100644 index 462d4141..00000000 --- a/tests/fixtures/multistandard/MySecondStandard/ruleset.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Dummy PHPCS standard for testing. - diff --git a/tests/fixtures/multistandard/composer.json b/tests/fixtures/multistandard/composer.json deleted file mode 100644 index f56d04c3..00000000 --- a/tests/fixtures/multistandard/composer.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name" : "phpcs-composer-installer/multistandard", - "description" : "Dummy PHPCS standard with multiple rulesets each in a subdirectory for use in the tests.", - "type" : "phpcodesniffer-standard", - "license" : "MIT", - "require" : { - "php" : ">=5.4", - "squizlabs/php_codesniffer" : "*", - "dealerdirect/phpcodesniffer-composer-installer" : "*" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -} diff --git a/tests/fixtures/no-ruleset/NoRuleset/ruleset.xml.dist b/tests/fixtures/no-ruleset/NoRuleset/ruleset.xml.dist deleted file mode 100644 index 15b517c7..00000000 --- a/tests/fixtures/no-ruleset/NoRuleset/ruleset.xml.dist +++ /dev/null @@ -1,5 +0,0 @@ - - - - Dummy PHPCS standard for testing. - diff --git a/tests/fixtures/no-ruleset/composer.json b/tests/fixtures/no-ruleset/composer.json deleted file mode 100644 index 33aa9ac4..00000000 --- a/tests/fixtures/no-ruleset/composer.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name" : "phpcs-composer-installer/no-ruleset", - "description" : "Dummy PHPCS standard without a ruleset for use in the tests.", - "type" : "phpcodesniffer-standard", - "license" : "MIT", - "require" : { - "php" : ">=5.4", - "squizlabs/php_codesniffer" : "*", - "dealerdirect/phpcodesniffer-composer-installer" : "*" - }, - "config": { - "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true - } - } -}