Exclude test files from class name rule#883
Merged
Conversation
* 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.
Includes unit tests.
Member
|
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 |
westonruter
approved these changes
Mar 21, 2017
Member
Author
|
@westonruter You only had to ask ;-) This wasn't difficult to implement at all. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It is common practice to name test file classes
test-something.php. This conflicts with the strict checking forclass-classname.phpfilenames.This PR changes the behaviour of the
FilenameSniffto exclude classes which extend (or are) well-known unit test classes from the class name check.The
custom_test_class_whitelistproperty should now also be available toFilenameSniffto 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:
is_token_in_test_method()method into two methods to be able to re-use the logic.FileNameSniffclass now extends theWordPress_Sniffclass to use the newis_test_class()method.Includes unit tests.
Fixes #882