Skip to content

Commit

Permalink
IsReferenceTest: add extra tests with intersection/DNF types
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed May 20, 2024
1 parent e5ac0d2 commit a631970
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Tests/BackCompat/BCFile/IsReferenceTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 38 additions & 3 deletions Tests/BackCompat/BCFile/IsReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,47 @@ class IsReferenceTest extends UtilityMethodTestCase
/**
* Test that false is returned when a non-"bitwise and" token is passed.
*
* @param string $testMarker Comment which precedes the test case.
* @param array<int|string> $targetTokens Type of tokens to look for.
*
* @dataProvider dataNotBitwiseAndToken
*
* @return void
*/
public function testNotBitwiseAndToken()
public function testNotBitwiseAndToken($testMarker, $targetTokens)
{
$testClass = static::TEST_CLASS;
$testClass = static::TEST_CLASS;
$targetTokens[] = T_BITWISE_AND;

$target = $this->getTargetToken('/* testBitwiseAndA */', T_STRING);
$target = $this->getTargetToken($testMarker, $targetTokens);
$this->assertFalse($testClass::isReference(self::$phpcsFile, $target));
}

/**
* Data provider.
*
* @see testNotBitwiseAndToken()
*
* @return array<string, array<string, string|array<int|string>>>
*/
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],
],
];
}

/**
* Test correctly identifying whether a "bitwise and" token is a reference or not.
*
Expand Down Expand Up @@ -364,6 +395,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,
Expand Down

0 comments on commit a631970

Please sign in to comment.