Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/Core/Tokenizers/PHP/GotoLabelTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ echo "i = $i";
end:
echo 'j hit 17';

switch($x){
case 3:
print($x);
if($x)
/* testGotoStatementInSwitch */
goto def;
default:
/* testGotoDeclarationInSwitch */
def:
print($x);
}

function hasGoto() {
if ($hide_form_and_script) {
/* testGotoStatementInFunction */
goto label;
}
?>

<form action="" method="post">
<!-- some HTML here -->
</form>

<?php
/* testGotoDeclarationInFunction */
label:
do_something();
}

switch ($x) {
/* testNotGotoDeclarationGlobalConstant */
case CONSTANT:
Expand Down
24 changes: 21 additions & 3 deletions tests/Core/Tokenizers/PHP/GotoLabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

use PHP_CodeSniffer\Tests\Core\Tokenizers\AbstractTokenizerTestCase;

/**
* Tests the tokenization of goto declarations and statements.
*
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
*/
final class GotoLabelTest extends AbstractTokenizerTestCase
{

Expand All @@ -22,7 +27,6 @@ final class GotoLabelTest extends AbstractTokenizerTestCase
* @param string $testContent The token content to expect.
*
* @dataProvider dataGotoStatement
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
*
* @return void
*/
Expand Down Expand Up @@ -56,6 +60,14 @@ public static function dataGotoStatement()
'testMarker' => '/* testGotoStatementInLoop */',
'testContent' => 'end',
],
'label for goto statement in switch' => [
'testMarker' => '/* testGotoStatementInSwitch */',
'testContent' => 'def',
],
'label for goto statement within function' => [
'testMarker' => '/* testGotoStatementInFunction */',
'testContent' => 'label',
],
];

}//end dataGotoStatement()
Expand All @@ -68,7 +80,6 @@ public static function dataGotoStatement()
* @param string $testContent The token content to expect.
*
* @dataProvider dataGotoDeclaration
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
*
* @return void
*/
Expand Down Expand Up @@ -102,6 +113,14 @@ public static function dataGotoDeclaration()
'testMarker' => '/* testGotoDeclarationOutsideLoop */',
'testContent' => 'end:',
],
'label in goto declaration - def' => [
'testMarker' => '/* testGotoDeclarationInSwitch */',
'testContent' => 'def:',
],
'label in goto declaration - label' => [
'testMarker' => '/* testGotoDeclarationInFunction */',
'testContent' => 'label:',
],
];

}//end dataGotoDeclaration()
Expand All @@ -114,7 +133,6 @@ public static function dataGotoDeclaration()
* @param string $testContent The token content to expect.
*
* @dataProvider dataNotAGotoDeclaration
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
*
* @return void
*/
Expand Down