diff --git a/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.inc b/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.inc index 71ef02897a..6df910beda 100644 --- a/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.inc +++ b/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.inc @@ -8,11 +8,12 @@ switch ($value) { default : echo 'other'; break; +/* testSwitchNormalSyntaxScopeCloser */ } // Test for https://github.com/squizlabs/PHP_CodeSniffer/issues/497 /* testSwitchAlternativeSyntax */ -switch ($value): +switch ($value) : /* testSwitchAlternativeSyntaxEnsureTestWillNotPickUpWrongColon */ case 1: echo 'one'; @@ -20,7 +21,7 @@ switch ($value): default: echo 'other'; break; -/* testSwitchAlternativeSyntaxEnd */ +/* testSwitchAlternativeSyntaxScopeCloser */ endswitch; // Test for https://github.com/squizlabs/PHP_CodeSniffer/issues/543 @@ -30,4 +31,30 @@ switch((function () { })()) /* testSwitchClosureWithinConditionScopeOpener */ { case 1: return 'test'; +/* testSwitchClosureWithinConditionScopeCloser */ } + +/* testSwitchClosureWithReturnTypeWithinCondition */ +switch((function (): string { + return 'bar'; +})()) /* testSwitchClosureWithReturnTypeWithinConditionScopeOpener */ : + /* testSwitchClosureWithReturnTypeWithinConditionEnsureTestWillNotPickUpWrongColon */ + case 1: + return 'test'; +/* testSwitchClosureWithReturnTypeWithinConditionScopeCloser */ +endswitch; + +/* testSwitchArrowFunctionWithinCondition */ +switch((fn() => $obj->{$foo . $bar})()) /* testSwitchArrowFunctionWithinConditionScopeOpener */ { + case 1: + return 'test'; +/* testSwitchArrowFunctionWithinConditionScopeCloser */ +} + +/* testSwitchArrowFunctionWithReturnTypeWithinCondition */ +switch((fn(): string => $condition ? 'foo' : 'bar')()) /* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeOpener */ : + /* testSwitchArrowFunctionWithReturnTypeWithinConditionEnsureTestWillNotPickUpWrongColon */ + case 1: + return 'test'; +/* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeCloser */ +endswitch; diff --git a/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.php b/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.php index 0977c0365c..f48b32401a 100644 --- a/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.php +++ b/tests/Core/Tokenizers/Tokenizer/RecurseScopeMapSwitchTokenScopeTest.php @@ -97,31 +97,61 @@ public function testSwitchScope($testMarker, $expectedTokens, $testOpenerMarker= public static function dataSwitchScope() { return [ - 'switch normal syntax' => [ - 'testMarker' => '/* testSwitchNormalSyntax */', - 'expectedTokens' => [ + 'switch normal syntax' => [ + 'testMarker' => '/* testSwitchNormalSyntax */', + 'expectedTokens' => [ 'scope_opener' => T_OPEN_CURLY_BRACKET, 'scope_closer' => T_CLOSE_CURLY_BRACKET, ], + 'testOpenerMarker' => null, + 'testCloserMarker' => '/* testSwitchNormalSyntaxScopeCloser */', ], - 'switch alternative syntax' => [ + 'switch alternative syntax' => [ 'testMarker' => '/* testSwitchAlternativeSyntax */', 'expectedTokens' => [ 'scope_opener' => T_COLON, 'scope_closer' => T_ENDSWITCH, ], 'testOpenerMarker' => null, - 'testCloserMarker' => '/* testSwitchAlternativeSyntaxEnd */', + 'testCloserMarker' => '/* testSwitchAlternativeSyntaxScopeCloser */', ], - 'switch with closure in the condition' => [ + 'switch with closure in the condition' => [ 'testMarker' => '/* testSwitchClosureWithinCondition */', 'expectedTokens' => [ 'scope_opener' => T_OPEN_CURLY_BRACKET, 'scope_closer' => T_CLOSE_CURLY_BRACKET, ], 'testOpenerMarker' => '/* testSwitchClosureWithinConditionScopeOpener */', - 'testCloserMarker' => '/* testSwitchClosureWithinConditionScopeOpener */', + 'testCloserMarker' => '/* testSwitchClosureWithinConditionScopeCloser */', + ], + 'switch alternative syntax with closure containing return type in the condition' => [ + 'testMarker' => '/* testSwitchClosureWithReturnTypeWithinCondition */', + 'expectedTokens' => [ + 'scope_opener' => T_COLON, + 'scope_closer' => T_ENDSWITCH, + ], + 'testOpenerMarker' => '/* testSwitchClosureWithReturnTypeWithinConditionScopeOpener */', + 'testCloserMarker' => '/* testSwitchClosureWithReturnTypeWithinConditionScopeCloser */', + ], + 'switch with arrow function in the condition' => [ + 'testMarker' => '/* testSwitchArrowFunctionWithinCondition */', + 'expectedTokens' => [ + 'scope_opener' => T_OPEN_CURLY_BRACKET, + 'scope_closer' => T_CLOSE_CURLY_BRACKET, + ], + 'testOpenerMarker' => '/* testSwitchArrowFunctionWithinConditionScopeOpener */', + 'testCloserMarker' => '/* testSwitchArrowFunctionWithinConditionScopeCloser */', ], + 'switch alternative syntax with arrow function containing return type in the condition' => [ + 'testMarker' => '/* testSwitchArrowFunctionWithReturnTypeWithinCondition */', + 'expectedTokens' => [ + 'scope_opener' => T_COLON, + 'scope_closer' => T_ENDSWITCH, + ], + 'testOpenerMarker' => '/* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeOpener */', + 'testCloserMarker' => '/* testSwitchArrowFunctionWithReturnTypeWithinConditionScopeCloser */', + ], + ]; }//end dataSwitchScope()