PHPCSStandards / composer-installer

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

Tests: add new RootPackageHandlingTest + bugfix #175

Closed jrfnl closed 2 years ago

jrfnl commented 2 years ago

Proposed Changes

TestCase: new recursiveDirectoryCopy() method

New helper method to recursively copy a (fixture) directory with all its files to another location, typically, one of the system temp test directories.

If the $srcDir contains a composer.json file, it will get the same TestCase::writeComposerJsonFile() special treatment, meaning that the artifacts directory will be injected, as well as plugin permissions and more.

Tests: add new RootPackageHandlingTest

This new test class tests that the plugin correctly registers standards found in the root package if it is an external standard.

Notes:

This test class covers the following bugs previously reported:

Plugin: only search root package when it has the phpcodesniffer-standard type (bug fix)

In the "olden days" of PHPCS 1.x, it was customary for projects to call their custom project ruleset ruleset.xml instead of [.]phpcs.xml[.dist].

This could lead to a root package with such an old-style PHPCS ruleset being registered as if it were a proper PHPCS external standard. This was previously reported in issue #32.

The fix I'm proposing now, applies the same rules as for vendor installed standards to the root package, i.e.:

Root packages which do not comply with both these rules will no longer be considered for registration with PHPCS. This should also make the plugin slightly faster for those packages which do not have external standards, but do have the plugin installed.

Includes removing some dead code (condition which could never be true) which was loosely related to this.

Fixes #32

Related Issues

Related to #92

jrfnl commented 2 years ago

Rebased without changes after the merge of #180 to get a clean and passing build. Will merge after the build passes.