diff --git a/tests/Core/File/IsReferenceTest.inc b/tests/Core/File/IsReferenceTest.inc index d371d6ef2d..05af839055 100644 --- a/tests/Core/File/IsReferenceTest.inc +++ b/tests/Core/File/IsReferenceTest.inc @@ -201,6 +201,12 @@ $closure = function &($param) use ($value) {}; /* testBitwiseAndArrowFunctionInDefault */ $fn = fn( $one = E_NOTICE & E_STRICT) => 1; +/* testIntersectionIsNotReference */ +function intersect(Foo&Bar $param) {} + +/* testDNFTypeIsNotReference */ +$fn = fn((Foo&\Bar)|null /* testParamPassByReference */ &$param) => $param; + /* testTokenizerIssue1284PHPCSlt280A */ if ($foo) {} [&$a, /* testTokenizerIssue1284PHPCSlt280B */ &$b] = $c; diff --git a/tests/Core/File/IsReferenceTest.php b/tests/Core/File/IsReferenceTest.php index 62eb600333..5b977de7ad 100644 --- a/tests/Core/File/IsReferenceTest.php +++ b/tests/Core/File/IsReferenceTest.php @@ -23,16 +23,50 @@ final class IsReferenceTest extends AbstractMethodUnitTest /** * Test that false is returned when a non-"bitwise and" token is passed. * + * @param string $testMarker Comment which precedes the test case. + * @param array $targetTokens Type of tokens to look for. + * + * @dataProvider dataNotBitwiseAndToken + * * @return void */ - public function testNotBitwiseAndToken() + public function testNotBitwiseAndToken($testMarker, $targetTokens) { - $target = $this->getTargetToken('/* testBitwiseAndA */', T_STRING); + $targetTokens[] = T_BITWISE_AND; + + $target = $this->getTargetToken($testMarker, $targetTokens); $this->assertFalse(self::$phpcsFile->isReference($target)); }//end testNotBitwiseAndToken() + /** + * Data provider. + * + * @see testNotBitwiseAndToken() + * + * @return array>> + */ + public static function dataNotBitwiseAndToken() + { + return [ + 'Not ampersand token at all' => [ + 'testMarker' => '/* testBitwiseAndA */', + 'targetTokens' => [T_STRING], + ], + 'ampersand in intersection type' => [ + 'testMarker' => '/* testIntersectionIsNotReference */', + 'targetTokens' => [T_TYPE_INTERSECTION], + ], + 'ampersand in DNF type' => [ + 'testMarker' => '/* testDNFTypeIsNotReference */', + 'targetTokens' => [T_TYPE_INTERSECTION], + ], + ]; + + }//end dataNotBitwiseAndToken() + + /** * Test correctly identifying whether a "bitwise and" token is a reference or not. * @@ -338,6 +372,10 @@ public static function dataIsReference() 'testMarker' => '/* testBitwiseAndArrowFunctionInDefault */', 'expected' => false, ], + 'reference: param pass by ref in arrow function' => [ + 'testMarker' => '/* testParamPassByReference */', + 'expected' => true, + ], 'issue-1284-short-list-directly-after-close-curly-control-structure' => [ 'testMarker' => '/* testTokenizerIssue1284PHPCSlt280A */', 'expected' => true,