YoastCS: add some test specific rules and exceptions #367
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.
YoastCS rules: selectively exempt test files [1]
While WordPressCS makes a best effort to try to prevent false positives on test code for the
WordPress.WP.GlobalVariablesOverride
, it is simpler to just plain exclude the test code from being scanned with this sniff.YoastCS rules: selectively exempt test files [2]
For mock-based unit tests, it is fine to use the PHP native
json_encode()
function to mock the WP/Yoast native alternative for this function, so let's prevent the test code needing lots of ignore annotations when the issue is not solvable.YoastCS rules: selectively exempt test files [3]
Double classes may overload methods from a parent class just to change the visibility of the method from
protected
topublic
to allow for testing the method directly. This is fine.YoastCS rules: enforce namespaces for all test files
Related to #303
Impact on Yoast packages:
YoastCS rules: enforce final classes for all test files
... while allowing
abstract
TestCases.Note: the typical/default "Doubles" directories within the "tests" directory are exempt from this rule as "Double" classes are often still combined with mocking and making the class
final
would break those tests.Related to #303
Impact on Yoast packages: