-
-
Notifications
You must be signed in to change notification settings - Fork 77
Tests/Tokenizer: expand default
keyword tests
#813
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
Tests/Tokenizer: expand default
keyword tests
#813
Conversation
|
||
function switchDefaultNestedIfWithAndWithoutBraces($i, $foo, $baz) { | ||
switch ($i) { | ||
/* testSwitchDefaultNestedIfWithAndWithoutBraces */ |
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.
The test has braces for all if/else leaves, while the point of the test was that it would not (also see the marker name)....
if ($foo) {
return true;
} elseif ($baz)
return true;
else {
echo 'else';
}
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 catching this. It is now fixed in f0e74de
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.
From the other PR:
Should this improvement also be done RecurseScopeMapDefaultKeywordConditionsTest tests ?
it seems to me that adding the closer markers to RecurseScopeMapDefaultKeywordConditionsTest is not necessary as the tests there are different. The code doesn't look for the scope_closer using AbstractTokenizerTestCase::getTargetToken() and the test marker. Instead, a closerOffset is passed, and it is used to determine the scope_closer:
I think that was the whole point of the original remark: having a marker for the closer will make the tests more stable, than manually setting closerOffset
expectations.
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.
This is what I meant: 82fae8e
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.
@jrfnl, thanks for clarifying and for providing an example. Besides the improvements from the commit that you mentioned, I believe I have seen the name of the marker included in the $message
parameter passed to the assertion methods in another test file. Something like:
$this->assertArrayHasKey(
'scope_condition',
$tokenArray,
sprintf('Scope condition is not set. Marker: %s.', $testMarker)
);
I like this pattern as it makes it easier to identify the related test case when there is a failure. Since I will improve RecurseScopeMapDefaultKeywordConditionsTest::testSwitchDefault()
in this PR, should I add the marker to the error message?
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.
@rodrigoprimo Sounds like a good idea 👍🏻
0a987db
to
b77716c
Compare
I marked this PR as "blocked" and created a separate PR to address a bug in the |
b77716c
to
6c0b405
Compare
@jrfnl, now that both PRs blocking this one have been merged, I have rebased it, fixed a merge conflict and now it is ready for another review. Thanks. |
public function testSwitchDefault( | ||
$testMarker, $testOpenerMarker=null, $testCloserMarker=null, $conditionStopMarker=null, $testContent='default', $sharedScopeCloser=false | ||
) { |
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.
Eh ... no. That's not how a multi-line function signature should look.
Moreover, I don't see a reason for a multi-line signature in the first place. We know we are in the tests, so the parameters don't need to tell us.
public function testSwitchDefault( | |
$testMarker, $testOpenerMarker=null, $testCloserMarker=null, $conditionStopMarker=null, $testContent='default', $sharedScopeCloser=false | |
) { | |
public function testSwitchDefault($testMarker, $openerMarker=null, $closerMarker=null, $conditionStopMarker=null, $testContent='default', $sharedScopeCloser=false) { |
Also, not so sure about the null
default values for the changed parameters. It doesn't make things clearer.
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.
We've discussed this PR in a call. The fourth commit is definitely not acceptable as-is (for various reasons).
The first commit (when combined with the second + fifth) is okay, though I'm in two minds about the new parameter for shared closers as it makes the test inconsistent with the sister-test for the case
keyword.
The third commit would be better off as a separate PR.
All in all, I don't think this is ready for merge.
This commit adds two new tests to the tokenizer tests for the `default` keyword: - Ensure that the `default` scope is set correctly when the scope closer is shared with a `switch`. - Ensure that the `default` scope is set correctly when there is an inner if condition with and without braces. Both tests were copied from similar tests for the `case` keyword that were added to protect against regressions (see b9809c7 and 61b9e9b).
6c0b405
to
9c70e44
Compare
Thanks for checking this PR, @jrfnl. I made the changes we discussed, combining commits 1, 2, and 5 into one and dropping commits 3 and 4. Could you please take another look? I will create another PR with commit 3 once this one is merged and then another PR for commit 4 after improving it. |
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 @rodrigoprimo ! This set of changes I can accept.
Description
This PR adds two new tests to the tokenizer tests for the
default
keyword:default
scope is set correctly when the scope closer is shared with aswitch
.default
scope is set correctly when there is an inner if condition with and without braces.Both tests were copied from similar tests for the
case
keyword that were added to protect against regressions (see b9809c7 and 61b9e9b). They were suggested in #595 (comment) and #595 (comment).Related issues/external references
Tests suggested in #595 (comment) and #595 (comment).
Types of changes
PR checklist