-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic/DisallowLongArraySyntax: improve code coverage #455
Generic/DisallowLongArraySyntax: improve code coverage #455
Conversation
@rodrigoprimo Thanks for another PR in this series.
I can 😎
While the tests I suggest in [2] and [3] don't test anything new, some redundancy is not necessarily a bad thing.
Good call. That condition is likely an artifact from when the Tokenizer didn't handle certain situations yet.
I think the tests on line 16 and 18 (and on line 25 for that matter) have a right to be included in this test case file as they use the I agree with you, though, that the tests on line 20 and 22 should probably be moved to the Tokenizer tests (if they aren't covered there already). You will find test artifacts like that in more test case files as prior to PHPCS 3.5.0, there were no dedicated tests for the Tokenizer at all. Until that time, the Tokenizer was only ever tested via the sniff tests. |
Thanks for the review, @jrfnl!
I believe the test in DisallowLongArraySyntaxUnitTest.2.inc covers the missing close parenthesis part of the condition, doesn't it?
I added another commit with the tests that you suggested and changed one of the existing tests to use the uppercase version of the
As we discussed via chat, I will work on a separate PR to add dedicated tokenizer tests for parameter types and return types. In this PR I will remove the tests on lines 20 and 22. |
Checked this out a little deeper and yes, you are right, the The test should be changed like the below diff to actually have value: -$var = array;
+$var = array |
Good catch. I had seen that the array keyword was not tokenized as T_ARRAY, but wrongly assumed that the same would happen without the semicolon. I decided to leave the semicolon as the original test contained it. This is fixed now. Could you please take another look? |
That test should now trigger a non-fixable error, but that expectation is not set in the test file, so the build would fail. |
ce5c1d2
to
d613dc4
Compare
Apologies, I forgot to include the changes to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing that. All good now. Thanks @rodrigoprimo !
I will rebase once I've merged the other PR and then merge this once the build has passed.
This commit moves an intentional parse error test to its own file. The parse error test did not trigger DisallowLongArraySyntaxSniff::process() as this sniff listen for T_ARRAY and the `array` keyword without parentheses is tokenized by PHPCS as T_STRING. Removing the semicolon fixes that and makes the test effective.
This commit uses a single isset() to check if two variables are set instead of using two isset() calls.
A check was added to the top of the file in 8d2a9dd to return an error early if the array is missing an opening and/or a closing parenthesis. This means that `$opener` can never be null as when the code reaches the point where this variable is set, `$tokens[$stackPtr]['parenthesis_opener']` cannot be null.
This commit adds two safeguard tests that do not trigger the sniff as they use the array keyword in a method definition and a method call. It also updates one of the existing tests to declare an array using array in uppercase. This is already handled correctly by PHPCS but it was not documented in a test.
d613dc4
to
e1f0e46
Compare
Description
This PR improves code coverage for the Generic.Arrays.DisallowLongArraySyntax sniff. It doesn't add any new tests as I couldn't think of any relevant missing tests. But it does remove an unreachable condition.
There are a few tests that I'm not sure if they belong to the sniff or not:
https://github.com/rodrigoprimo/PHP_CodeSniffer/blob/8f31c91c4a520d52ec97d819a7ce9d7da5b3fb40/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc#L16-L22
They were added in ee0f59c and it seems this commit is about a change in the PHP Tokenizer, so I wonder if those tests should be moved to the PHP Tokenizer tests?
Related issues/external references
Part of #146
Types of changes
PR checklist