From b76eb2b7bb3b8f76e9cc3df47eb897d6c3d5e069 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Mon, 12 Aug 2024 17:16:12 -0300 Subject: [PATCH] Tests/Tokenizer: test related to setting the scope for T_CASE This commit copies a sniff test from InlineControlStructureUnitTest.php to the Tokenizer::recurseScopeMap() tests for the case keyword. This test was added in 65ef053 before the Tokenizer tests were created. It ensures that the scope for the T_CASE token is set correctly when there is a inline control structure inside it with more than three lines. --- .../RecurseScopeMapCaseKeywordConditionsTest.inc | 13 +++++++++++++ .../RecurseScopeMapCaseKeywordConditionsTest.php | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc index 3b3199cb35..43f9118393 100644 --- a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc +++ b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.inc @@ -117,3 +117,16 @@ switch ($type) { } break; } + +// Test for https://github.com/squizlabs/PHP_CodeSniffer/issues/1590 +switch ($num) { + /* testSwitchCaseNestedInlineIfWithMoreThanThreeLines */ + case 0: + if (1 > $num) + return bar( + baz( + "foobarbaz" + ) + ); + break; +} diff --git a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php index 819d410020..b638c5ff3e 100644 --- a/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php +++ b/tests/Core/Tokenizer/Tokenizer/RecurseScopeMapCaseKeywordConditionsTest.php @@ -208,6 +208,13 @@ public static function dataNotEnumCases() 'scope_closer' => T_BREAK, ], ], + 'switch case, nested inline if' => [ + 'testMarker' => '/* testSwitchCaseNestedInlineIfWithMoreThanThreeLines */', + 'expectedTokens' => [ + 'scope_opener' => T_COLON, + 'scope_closer' => T_BREAK, + ], + ], ]; }//end dataNotEnumCases()