Skip to content

Commit 99e3049

Browse files
committed
Add test for compact used within arrow function
1 parent 8d402fc commit 99e3049

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Tests/VariableAnalysisSniff/VariableAnalysisTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ public function testCompactWarnings()
522522
23,
523523
26,
524524
36,
525+
41,
526+
42,
525527
];
526528
$this->assertSame($expectedWarnings, $lines);
527529
}
@@ -543,6 +545,8 @@ public function testCompactWarningsHaveCorrectSniffCodes()
543545
$this->assertSame(self::UNDEFINED_ERROR_CODE, $warnings[26][66][0]['source']);
544546
$this->assertSame(self::UNUSED_ERROR_CODE, $warnings[36][5][0]['source']);
545547
$this->assertSame(self::UNDEFINED_ERROR_CODE, $warnings[36][23][0]['source']);
548+
$this->assertSame(self::UNUSED_ERROR_CODE, $warnings[41][22][0]['source']);
549+
$this->assertSame(self::UNDEFINED_ERROR_CODE, $warnings[42][39][0]['source']);
546550
}
547551

548552
public function testTraitAllowsThis()

Tests/VariableAnalysisSniff/fixtures/CompactFixture.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ function foo() {
3535
$a = 'Hello';
3636
$c = compact( $a, $b ); // Unused variable c and undefined variable b
3737
}
38+
39+
function function_with_arrow_function_and_compact() {
40+
$make_array = fn ($arg) => compact('arg');
41+
$make_nothing = fn ($arg) => []; // Unused variable $arg
42+
$make_no_variable = fn () => compact('arg') // Undefined variable $arg
43+
echo $make_array('hello');
44+
echo $make_nothing('hello');
45+
echo $make_no_variable();
46+
$make_array_multiple = fn ($arg1, $arg2, $arg3) => compact('arg1', 'arg2', 'arg3');
47+
echo $make_array_multiple();
48+
}

0 commit comments

Comments
 (0)