Skip to content

Commit 83f3859

Browse files
authored
Merge pull request #460 from PHPCSStandards/feature/tests-arrow-functions-vs-intersection-types
Tokenizer/PHP: add tests for arrow functions with intersection types
2 parents b0d2d61 + 273959e commit 83f3859

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
@@ -113,6 +113,12 @@ $arrowWithUnionReturn = fn($param) : int|true => $param | 10;
113113
/* testUnionReturnTypeWithFalse */
114114
$arrowWithUnionReturn = fn($param) : string|FALSE => $param | 10;
115115

116+
/* testIntersectionParamType */
117+
$arrowWithUnionParam = fn(Traversable&Countable $param) : int => (new SomeClass($param))->getValue();
118+
119+
/* testIntersectionReturnType */
120+
$arrowWithUnionReturn = fn($param) : \MyFoo&SomeInterface => new SomeClass($param);
121+
116122
/* testTernary */
117123
$fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b';
118124

tests/Core/Tokenizer/BackfillFnTokenTest.php

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

517517

518+
/**
519+
* Test arrow function with an intersection parameter type.
520+
*
521+
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
522+
*
523+
* @return void
524+
*/
525+
public function testIntersectionParamType()
526+
{
527+
$token = $this->getTargetToken('/* testIntersectionParamType */', T_FN);
528+
$this->backfillHelper($token);
529+
$this->scopePositionTestHelper($token, 13, 27);
530+
531+
}//end testIntersectionParamType()
532+
533+
534+
/**
535+
* Test arrow function with an intersection return type.
536+
*
537+
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
538+
*
539+
* @return void
540+
*/
541+
public function testIntersectionReturnType()
542+
{
543+
$token = $this->getTargetToken('/* testIntersectionReturnType */', T_FN);
544+
$this->backfillHelper($token);
545+
$this->scopePositionTestHelper($token, 12, 20);
546+
547+
}//end testIntersectionReturnType()
548+
549+
518550
/**
519551
* Test arrow functions used in ternary operators.
520552
*

0 commit comments

Comments
 (0)