Skip to content

Commit 28530a0

Browse files
committed
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 5e5e6dc commit 28530a0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php
22

33
/* testSwitchNormalSyntax */
4-
switch ($value) {
4+
switch ($value) /* testSwitchNormalSyntaxScopeOpener */ {
55
case 1:
66
echo 'one';
77
break;
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-
/* testSwitchAlternativeSyntaxEnsureTestWillNotPickUpWrongColon */
16+
switch ($value) /* testSwitchAlternativeSyntaxScopeOpener */ :
1717
case 1:
1818
echo 'one';
1919
break;
2020
default:
2121
echo 'other';
2222
break;
23-
/* testSwitchAlternativeSyntaxEnd */
23+
/* testSwitchAlternativeSyntaxScopeCloser */
2424
endswitch;
2525

2626
// Test for https://github.com/squizlabs/PHP_CodeSniffer/issues/543
@@ -30,4 +30,5 @@ switch((function () {
3030
})()) /* testSwitchClosureWithinConditionScopeOpener */ {
3131
case 1:
3232
return 'test';
33+
/* testSwitchClosureWithinConditionScopeCloser */
3334
}

tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,22 @@ 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' => '/* testSwitchNormalSyntaxScopeOpener */',
107+
'testCloserMarker' => '/* testSwitchNormalSyntaxScopeCloser */',
106108
],
107109
'switch alternative syntax' => [
108110
'testMarker' => '/* testSwitchAlternativeSyntax */',
109111
'expectedTokens' => [
110112
'scope_opener' => T_COLON,
111113
'scope_closer' => T_ENDSWITCH,
112114
],
113-
'testOpenerMarker' => null,
114-
'testCloserMarker' => '/* testSwitchAlternativeSyntaxEnd */',
115+
'testOpenerMarker' => '/* testSwitchAlternativeSyntaxScopeOpener */',
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)