Ruleset Tests: revert 485 and fix it#509
Merged
Conversation
In 485, three tests were commented out because they seemed to break the ruleset tests.
At the request of Gary, I've had a look see to try and find the underlying cause.
Turned out to be a combination of three things:
1. A new warning having been introduced in PHP 7.4 about using array access on non-arrays.
2. The code in the test case file being incomplete/incorrect - required parameters for function calls were missing.
3. The WPCS `EscapeOutput` not having enough defensive coding for when a faulty function call without parameters would be encountered.
Obviously we can't do anything about 1.
As for 3, I've opened a PR in WPCS upstream to fix this, but that fix won't be available to VIP until WPCS 3.0.0 has been released and VIPCS upgrades.
See: WordPress/WordPress-Coding-Standards 1939
So, in the mean time, let's make sure the function calls in the test case file which aren't intended to trigger the `EscapeOutput` sniff, don't trigger it.
And that's what's done in this PR.
---
To reproduce my findings / How to investigate this in the future:
* Make sure you are set up to use PHP 7.4.x (or whatever other PHP version where the issue was first seen).
* Run `phpcs -ps --severity=1 --standard=WordPressVIPMinimum ./WordPressVIPMinimum/ruleset-test.inc`
* Take note of the missing errors/warnings.
* Scroll to the top of the full report and see the cause:
```
1 | ERROR | An error occurred during processing; checking has been aborted. The error message was: Trying to access array offset on value of type bool
| | in path/to/WordPress/Sniffs/Security/EscapeOutputSniff.php on line 198 (Internal.Exception)
```
GaryJones
approved these changes
Jul 22, 2020
Contributor
GaryJones
left a comment
There was a problem hiding this comment.
Ouch - what an awkward combination of reasons. Thanks for reviewing and getting to the bottom of it :-)
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.
In #485, three tests were commented out because they seemed to break the ruleset tests.
At the request of Gary, I've had a look see to try and find the underlying cause.
Turned out to be a combination of three things:
EscapeOutputnot having enough defensive coding for when a faulty function call without parameters would be encountered.Obviously we can't do anything about 1.
As for 3, I've opened a PR in WPCS upstream to fix this, but that fix won't be available to VIP until WPCS 3.0.0 has been released and VIPCS upgrades.
See: WordPress/WordPress-Coding-Standards#1939
So, in the mean time, let's make sure the function calls in the test case file which aren't intended to trigger the
EscapeOutputsniff, don't trigger it.And that's what's done in this PR.
To reproduce my findings / How to investigate this in the future:
phpcs -ps --severity=1 --standard=WordPressVIPMinimum ./WordPressVIPMinimum/ruleset-test.inc