Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/Core/File/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
42 changes: 40 additions & 2 deletions tests/Core/File/IsReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int|string> $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<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],
],
];

}//end dataNotBitwiseAndToken()


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