Skip to content

Commit eb6b059

Browse files
authored
Merge pull request #918 from PHPCSStandards/feature/gotolabeltest-add-extra-tests
GotoLabelTest: add some more tests
2 parents b5c80d3 + 489baa9 commit eb6b059

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

tests/Core/Tokenizers/PHP/GotoLabelTest.inc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,35 @@ echo "i = $i";
2323
end:
2424
echo 'j hit 17';
2525

26+
switch($x){
27+
case 3:
28+
print($x);
29+
if($x)
30+
/* testGotoStatementInSwitch */
31+
goto def;
32+
default:
33+
/* testGotoDeclarationInSwitch */
34+
def:
35+
print($x);
36+
}
37+
38+
function hasGoto() {
39+
if ($hide_form_and_script) {
40+
/* testGotoStatementInFunction */
41+
goto label;
42+
}
43+
?>
44+
45+
<form action="" method="post">
46+
<!-- some HTML here -->
47+
</form>
48+
49+
<?php
50+
/* testGotoDeclarationInFunction */
51+
label:
52+
do_something();
53+
}
54+
2655
switch ($x) {
2756
/* testNotGotoDeclarationGlobalConstant */
2857
case CONSTANT:

tests/Core/Tokenizers/PHP/GotoLabelTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
use PHP_CodeSniffer\Tests\Core\Tokenizers\AbstractTokenizerTestCase;
1313

14+
/**
15+
* Tests the tokenization of goto declarations and statements.
16+
*
17+
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
18+
*/
1419
final class GotoLabelTest extends AbstractTokenizerTestCase
1520
{
1621

@@ -22,7 +27,6 @@ final class GotoLabelTest extends AbstractTokenizerTestCase
2227
* @param string $testContent The token content to expect.
2328
*
2429
* @dataProvider dataGotoStatement
25-
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
2630
*
2731
* @return void
2832
*/
@@ -56,6 +60,14 @@ public static function dataGotoStatement()
5660
'testMarker' => '/* testGotoStatementInLoop */',
5761
'testContent' => 'end',
5862
],
63+
'label for goto statement in switch' => [
64+
'testMarker' => '/* testGotoStatementInSwitch */',
65+
'testContent' => 'def',
66+
],
67+
'label for goto statement within function' => [
68+
'testMarker' => '/* testGotoStatementInFunction */',
69+
'testContent' => 'label',
70+
],
5971
];
6072

6173
}//end dataGotoStatement()
@@ -68,7 +80,6 @@ public static function dataGotoStatement()
6880
* @param string $testContent The token content to expect.
6981
*
7082
* @dataProvider dataGotoDeclaration
71-
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
7283
*
7384
* @return void
7485
*/
@@ -102,6 +113,14 @@ public static function dataGotoDeclaration()
102113
'testMarker' => '/* testGotoDeclarationOutsideLoop */',
103114
'testContent' => 'end:',
104115
],
116+
'label in goto declaration - def' => [
117+
'testMarker' => '/* testGotoDeclarationInSwitch */',
118+
'testContent' => 'def:',
119+
],
120+
'label in goto declaration - label' => [
121+
'testMarker' => '/* testGotoDeclarationInFunction */',
122+
'testContent' => 'label:',
123+
],
105124
];
106125

107126
}//end dataGotoDeclaration()
@@ -114,7 +133,6 @@ public static function dataGotoDeclaration()
114133
* @param string $testContent The token content to expect.
115134
*
116135
* @dataProvider dataNotAGotoDeclaration
117-
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
118136
*
119137
* @return void
120138
*/

0 commit comments

Comments
 (0)