Skip to content

Commit 2f8ed54

Browse files
committed
Tokenizer/PHP: add tests for arrow functions with intersection types
This was already handled correctly by the Tokenizer, but not safeguarded via tests.
1 parent 130fdcb commit 2f8ed54

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/Core/Tokenizer/BackfillFnTokenTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ $arrowWithUnionReturn = fn($param) : int|true => $param | 10;
119119
/* testUnionReturnTypeWithFalse */
120120
$arrowWithUnionReturn = fn($param) : string|FALSE => $param | 10;
121121

122+
/* testIntersectionParamType */
123+
$arrowWithUnionParam = fn(Traversable&Countable $param) : int => (new SomeClass($param))->getValue();
124+
125+
/* testIntersectionReturnType */
126+
$arrowWithUnionReturn = fn($param) : \MyFoo&SomeInterface => new SomeClass($param);
127+
122128
/* testTernary */
123129
$fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b';
124130

tests/Core/Tokenizer/BackfillFnTokenTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,38 @@ public function testUnionReturnTypeWithFalse()
571571
}//end testUnionReturnTypeWithFalse()
572572

573573

574+
/**
575+
* Test arrow function with an intersection parameter type.
576+
*
577+
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
578+
*
579+
* @return void
580+
*/
581+
public function testIntersectionParamType()
582+
{
583+
$token = $this->getTargetToken('/* testIntersectionParamType */', T_FN);
584+
$this->backfillHelper($token);
585+
$this->scopePositionTestHelper($token, 13, 27);
586+
587+
}//end testIntersectionParamType()
588+
589+
590+
/**
591+
* Test arrow function with an intersection return type.
592+
*
593+
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
594+
*
595+
* @return void
596+
*/
597+
public function testIntersectionReturnType()
598+
{
599+
$token = $this->getTargetToken('/* testIntersectionReturnType */', T_FN);
600+
$this->backfillHelper($token);
601+
$this->scopePositionTestHelper($token, 11, 19);
602+
603+
}//end testIntersectionReturnType()
604+
605+
574606
/**
575607
* Test arrow functions used in ternary operators.
576608
*

0 commit comments

Comments
 (0)