Skip to content

Commit 7954ce3

Browse files
rodrigoprimojrfnl
authored andcommitted
Tests/Tokenizer: improve stability of the switch keyword tests
This commits improves the stability of the switch keyword tests by ensuring that specific markers are used to get the scope closer and scope opener tokens.
1 parent bf2b64d commit 7954ce3

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ switch ($value) {
88
default :
99
echo 'other';
1010
break;
11+
/* testSwitchNormalSyntaxScopeCloser */
1112
}
1213

1314
// Test for https://github.com/squizlabs/PHP_CodeSniffer/issues/497
1415
/* testSwitchAlternativeSyntax */
15-
switch ($value):
16+
switch ($value) :
1617
/* testSwitchAlternativeSyntaxEnsureTestWillNotPickUpWrongColon */
1718
case 1:
1819
echo 'one';
1920
break;
2021
default:
2122
echo 'other';
2223
break;
23-
/* testSwitchAlternativeSyntaxEnd */
24+
/* testSwitchAlternativeSyntaxScopeCloser */
2425
endswitch;
2526

2627
// Test for https://github.com/squizlabs/PHP_CodeSniffer/issues/543
@@ -30,4 +31,5 @@ switch((function () {
3031
})()) /* testSwitchClosureWithinConditionScopeOpener */ {
3132
case 1:
3233
return 'test';
34+
/* testSwitchClosureWithinConditionScopeCloser */
3335
}

tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ public static function dataSwitchScope()
9898
{
9999
return [
100100
'switch normal syntax' => [
101-
'testMarker' => '/* testSwitchNormalSyntax */',
102-
'expectedTokens' => [
101+
'testMarker' => '/* testSwitchNormalSyntax */',
102+
'expectedTokens' => [
103103
'scope_opener' => T_OPEN_CURLY_BRACKET,
104104
'scope_closer' => T_CLOSE_CURLY_BRACKET,
105105
],
106+
'testOpenerMarker' => null,
107+
'testCloserMarker' => '/* testSwitchNormalSyntaxScopeCloser */',
106108
],
107109
'switch alternative syntax' => [
108110
'testMarker' => '/* testSwitchAlternativeSyntax */',
@@ -111,7 +113,7 @@ public static function dataSwitchScope()
111113
'scope_closer' => T_ENDSWITCH,
112114
],
113115
'testOpenerMarker' => null,
114-
'testCloserMarker' => '/* testSwitchAlternativeSyntaxEnd */',
116+
'testCloserMarker' => '/* testSwitchAlternativeSyntaxScopeCloser */',
115117
],
116118
'switch with closure in the condition' => [
117119
'testMarker' => '/* testSwitchClosureWithinCondition */',
@@ -120,7 +122,7 @@ public static function dataSwitchScope()
120122
'scope_closer' => T_CLOSE_CURLY_BRACKET,
121123
],
122124
'testOpenerMarker' => '/* testSwitchClosureWithinConditionScopeOpener */',
123-
'testCloserMarker' => '/* testSwitchClosureWithinConditionScopeOpener */',
125+
'testCloserMarker' => '/* testSwitchClosureWithinConditionScopeCloser */',
124126
],
125127
];
126128

0 commit comments

Comments
 (0)