diff --git a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc index a4bb911997..6c71d80db0 100644 --- a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc +++ b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc @@ -103,3 +103,17 @@ switch ($value): case 1: echo 'one'; endswitch; + +// Test for https://github.com/squizlabs/PHP_CodeSniffer/issues/879 +switch ($type) { + /* testSwitchCaseNestedIfWithAndWithoutBraces */ + case 1: + if ($foo) { + return true; + } elseif ($baz) + return true; + else { + echo 'else'; + } + break; +} diff --git a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php index 40e3dc90db..985f4f481e 100644 --- a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php +++ b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php @@ -139,14 +139,14 @@ public function testNotEnumCases($testMarker, $expectedTokens, $testCloserMarker public static function dataNotEnumCases() { return [ - 'switch case with constant, semicolon condition end' => [ + 'switch case with constant, semicolon condition end' => [ 'testMarker' => '/* testCaseWithSemicolonIsNotEnumCase */', 'expectedTokens' => [ 'scope_opener' => T_SEMICOLON, 'scope_closer' => T_CLOSE_CURLY_BRACKET, ], ], - 'switch case with constant, colon condition end' => [ + 'switch case with constant, colon condition end' => [ 'testMarker' => '/* testCaseWithConstantIsNotEnumCase */', 'expectedTokens' => [ 'scope_opener' => T_COLON, @@ -154,7 +154,7 @@ public static function dataNotEnumCases() ], 'testCloserMarker' => '/* testCaseConstantCloserMarker */', ], - 'switch case with constant, comparison' => [ + 'switch case with constant, comparison' => [ 'testMarker' => '/* testCaseWithConstantAndIdenticalIsNotEnumCase */', 'expectedTokens' => [ 'scope_opener' => T_COLON, @@ -162,7 +162,7 @@ public static function dataNotEnumCases() ], 'testCloserMarker' => '/* testCaseConstantCloserMarker */', ], - 'switch case with constant, assignment' => [ + 'switch case with constant, assignment' => [ 'testMarker' => '/* testCaseWithAssigmentToConstantIsNotEnumCase */', 'expectedTokens' => [ 'scope_opener' => T_COLON, @@ -170,7 +170,7 @@ public static function dataNotEnumCases() ], 'testCloserMarker' => '/* testCaseConstantCloserMarker */', ], - 'switch case with constant, keyword in mixed case' => [ + 'switch case with constant, keyword in mixed case' => [ 'testMarker' => '/* testIsNotEnumCaseIsCaseInsensitive */', 'expectedTokens' => [ 'scope_opener' => T_COLON, @@ -178,7 +178,7 @@ public static function dataNotEnumCases() ], 'testCloserMarker' => '/* testCaseConstantCloserMarker */', ], - 'switch case, body in curlies declares enum' => [ + 'switch case, body in curlies declares enum' => [ 'testMarker' => '/* testCaseInSwitchWhenCreatingEnumInSwitch1 */', 'expectedTokens' => [ 'scope_opener' => T_OPEN_CURLY_BRACKET, @@ -186,7 +186,7 @@ public static function dataNotEnumCases() ], 'testCloserMarker' => '/* testCaseInSwitchWhenCreatingEnumInSwitch1CloserMarker */', ], - 'switch case, body after semicolon declares enum' => [ + 'switch case, body after semicolon declares enum' => [ 'testMarker' => '/* testCaseInSwitchWhenCreatingEnumInSwitch2 */', 'expectedTokens' => [ 'scope_opener' => T_SEMICOLON, @@ -194,13 +194,20 @@ public static function dataNotEnumCases() ], 'testCloserMarker' => '/* testCaseInSwitchWhenCreatingEnumInSwitch2CloserMarker */', ], - 'switch case, shared closer with switch' => [ + 'switch case, shared closer with switch' => [ 'testMarker' => '/* testSwitchCaseScopeCloserSharedWithSwitch */', 'expectedTokens' => [ 'scope_opener' => T_COLON, 'scope_closer' => T_ENDSWITCH, ], ], + 'switch case, nested inline if/elseif/else with and without braces' => [ + 'testMarker' => '/* testSwitchCaseNestedIfWithAndWithoutBraces */', + 'expectedTokens' => [ + 'scope_opener' => T_COLON, + 'scope_closer' => T_BREAK, + ], + ], ]; }//end dataNotEnumCases()