From 273959e246933750cc36781a6b465d2b777f074d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 18 Apr 2024 06:18:25 +0200 Subject: [PATCH] Tokenizer/PHP: add tests for arrow functions with intersection types This was already handled correctly by the Tokenizer, but not safeguarded via tests. --- tests/Core/Tokenizer/BackfillFnTokenTest.inc | 6 ++++ tests/Core/Tokenizer/BackfillFnTokenTest.php | 32 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tests/Core/Tokenizer/BackfillFnTokenTest.inc b/tests/Core/Tokenizer/BackfillFnTokenTest.inc index 6cf44229cc..63f9326836 100644 --- a/tests/Core/Tokenizer/BackfillFnTokenTest.inc +++ b/tests/Core/Tokenizer/BackfillFnTokenTest.inc @@ -113,6 +113,12 @@ $arrowWithUnionReturn = fn($param) : int|true => $param | 10; /* testUnionReturnTypeWithFalse */ $arrowWithUnionReturn = fn($param) : string|FALSE => $param | 10; +/* testIntersectionParamType */ +$arrowWithUnionParam = fn(Traversable&Countable $param) : int => (new SomeClass($param))->getValue(); + +/* testIntersectionReturnType */ +$arrowWithUnionReturn = fn($param) : \MyFoo&SomeInterface => new SomeClass($param); + /* testTernary */ $fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b'; diff --git a/tests/Core/Tokenizer/BackfillFnTokenTest.php b/tests/Core/Tokenizer/BackfillFnTokenTest.php index 5ad4e1b95a..f394276a7c 100644 --- a/tests/Core/Tokenizer/BackfillFnTokenTest.php +++ b/tests/Core/Tokenizer/BackfillFnTokenTest.php @@ -515,6 +515,38 @@ public function testUnionReturnTypeWithFalse() }//end testUnionReturnTypeWithFalse() + /** + * Test arrow function with an intersection parameter type. + * + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testIntersectionParamType() + { + $token = $this->getTargetToken('/* testIntersectionParamType */', T_FN); + $this->backfillHelper($token); + $this->scopePositionTestHelper($token, 13, 27); + + }//end testIntersectionParamType() + + + /** + * Test arrow function with an intersection return type. + * + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional + * + * @return void + */ + public function testIntersectionReturnType() + { + $token = $this->getTargetToken('/* testIntersectionReturnType */', T_FN); + $this->backfillHelper($token); + $this->scopePositionTestHelper($token, 12, 20); + + }//end testIntersectionReturnType() + + /** * Test arrow functions used in ternary operators. *