Skip to content

Commit 6119828

Browse files
authored
Merge pull request #470 from PHPCSStandards/php-8.2/file-isreference-add-tests-with-dnf-types
IsReferenceTest: add extra tests with intersection/DNF types
2 parents f41285a + e8dea90 commit 6119828

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

tests/Core/File/IsReferenceTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ $closure = function &($param) use ($value) {};
201201
/* testBitwiseAndArrowFunctionInDefault */
202202
$fn = fn( $one = E_NOTICE & E_STRICT) => 1;
203203

204+
/* testIntersectionIsNotReference */
205+
function intersect(Foo&Bar $param) {}
206+
207+
/* testDNFTypeIsNotReference */
208+
$fn = fn((Foo&\Bar)|null /* testParamPassByReference */ &$param) => $param;
209+
204210
/* testTokenizerIssue1284PHPCSlt280A */
205211
if ($foo) {}
206212
[&$a, /* testTokenizerIssue1284PHPCSlt280B */ &$b] = $c;

tests/Core/File/IsReferenceTest.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,50 @@ final class IsReferenceTest extends AbstractMethodUnitTest
2323
/**
2424
* Test that false is returned when a non-"bitwise and" token is passed.
2525
*
26+
* @param string $testMarker Comment which precedes the test case.
27+
* @param array<int|string> $targetTokens Type of tokens to look for.
28+
*
29+
* @dataProvider dataNotBitwiseAndToken
30+
*
2631
* @return void
2732
*/
28-
public function testNotBitwiseAndToken()
33+
public function testNotBitwiseAndToken($testMarker, $targetTokens)
2934
{
30-
$target = $this->getTargetToken('/* testBitwiseAndA */', T_STRING);
35+
$targetTokens[] = T_BITWISE_AND;
36+
37+
$target = $this->getTargetToken($testMarker, $targetTokens);
3138
$this->assertFalse(self::$phpcsFile->isReference($target));
3239

3340
}//end testNotBitwiseAndToken()
3441

3542

43+
/**
44+
* Data provider.
45+
*
46+
* @see testNotBitwiseAndToken()
47+
*
48+
* @return array<string, array<string, string|array<int|string>>>
49+
*/
50+
public static function dataNotBitwiseAndToken()
51+
{
52+
return [
53+
'Not ampersand token at all' => [
54+
'testMarker' => '/* testBitwiseAndA */',
55+
'targetTokens' => [T_STRING],
56+
],
57+
'ampersand in intersection type' => [
58+
'testMarker' => '/* testIntersectionIsNotReference */',
59+
'targetTokens' => [T_TYPE_INTERSECTION],
60+
],
61+
'ampersand in DNF type' => [
62+
'testMarker' => '/* testDNFTypeIsNotReference */',
63+
'targetTokens' => [T_TYPE_INTERSECTION],
64+
],
65+
];
66+
67+
}//end dataNotBitwiseAndToken()
68+
69+
3670
/**
3771
* Test correctly identifying whether a "bitwise and" token is a reference or not.
3872
*
@@ -338,6 +372,10 @@ public static function dataIsReference()
338372
'testMarker' => '/* testBitwiseAndArrowFunctionInDefault */',
339373
'expected' => false,
340374
],
375+
'reference: param pass by ref in arrow function' => [
376+
'testMarker' => '/* testParamPassByReference */',
377+
'expected' => true,
378+
],
341379
'issue-1284-short-list-directly-after-close-curly-control-structure' => [
342380
'testMarker' => '/* testTokenizerIssue1284PHPCSlt280A */',
343381
'expected' => true,

0 commit comments

Comments
 (0)