Skip to content

Exclude test files from class name rule#883

Merged
JDGrimes merged 3 commits intodevelopfrom
feature/issue-882-exclude-test-files-from-class-name-rule
Mar 21, 2017
Merged

Exclude test files from class name rule#883
JDGrimes merged 3 commits intodevelopfrom
feature/issue-882-exclude-test-files-from-class-name-rule

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Mar 21, 2017

It is common practice to name test file classes test-something.php. This conflicts with the strict checking for class-classname.php filenames.

This PR changes the behaviour of the FilenameSniff to exclude classes which extend (or are) well-known unit test classes from the class name check.

The custom_test_class_whitelist property should now also be available to FilenameSniff to allow for whitelisting additional test classes.
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#global-variable-overloads-in-unit-tests

Notes:

  • Split the is_token_in_test_method() method into two methods to be able to re-use the logic.
  • Added the PHPUnit6 base test class to the whitelist.
  • The FileNameSniff class now extends the WordPress_Sniff class to use the new is_test_class() method.
  • Leveraged use of the class.
  • Don't apply strict class name rules for test files.

Includes unit tests.

Fixes #882

jrfnl added 3 commits March 21, 2017 17:30
* Split the `is_token_in_test_method()` method into two methods to be able to re-use the logic.
* Added the PHPUnit6 base test class to the whitelist.
The `FileNameSniff` class now extends the `WordPress_Sniff` class to use the new `is_test_class()` method.

Leveraged use of the class.
@westonruter
Copy link
Member

westonruter commented Mar 21, 2017

YES! Oh yes. I've had to turn this sniff off for test files: https://github.com/WP-API/wp-api-customize-endpoints/blob/f17ebdb/phpcs.ruleset.xml#L26-L28

@jrfnl
Copy link
Member Author

jrfnl commented Mar 21, 2017

@westonruter You only had to ask ;-) This wasn't difficult to implement at all.

@JDGrimes JDGrimes merged commit fc89f87 into develop Mar 21, 2017
@JDGrimes JDGrimes deleted the feature/issue-882-exclude-test-files-from-class-name-rule branch March 21, 2017 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants