Skip to content

Commit 7723d59

Browse files
committed
Tests/Tokenizer: fix conditions checking range in T_DEFAULT test
Among other things, the RecurseScopeMapDefaultKeywordConditionsTest ::testSwitchDefault() method checks if tokens within the scope of a `T_DEFAULT` token have `T_DEFAULT` set as one of its `conditions` array. The test was incorrectly checking token `conditions` due to an off-by-one error in the loop range when the `T_DEFAULT` uses curly braces. For a `T_DEFAULT` with curly braces, the tokenizer adds `T_DEFAULT` to the `conditions` array of all the tokens within its scope up to the `T_BREAK|T_RETURN|T_CONTINUE`, but the test was checking only until the token before the `T_BREAK|T_RETURN|T_CONTINUE`. While for a `T_DEFAULT` without curly braces, it adds to all the tokens within the scope until the token before the scope closer. This commit updates the test to ensure that all tokens within a default case scope that should have the `T_DEFAULT` token in their `conditions` array are properly checked. To achieve that the loop was modified: - The end point ($end) is now set to `$closer - 1` when curly braces are not used. - The loop condition uses inclusive comparison (<=) to ensure that the `$end` is also checked.
1 parent 08a864f commit 7723d59

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/Core/Tokenizers/Tokenizer/RecurseScopeMapDefaultKeywordConditionsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ public function testSwitchDefault($testMarker, $openerOffset, $closerOffset, $co
157157
$this->assertSame($expectedScopeCloser, $tokens[$closer]['scope_closer'], 'T_DEFAULT closer scope closer token incorrect');
158158

159159
if (($opener + 1) !== $closer) {
160-
$end = $closer;
160+
$end = ($closer - 1);
161161
if (isset($conditionStop) === true) {
162162
$end = ($token + $conditionStop);
163163
}
164164

165-
for ($i = ($opener + 1); $i < $end; $i++) {
165+
for ($i = ($opener + 1); $i <= $end; $i++) {
166166
$this->assertArrayHasKey(
167167
$token,
168168
$tokens[$i]['conditions'],

0 commit comments

Comments
 (0)