Skip to content

Commit 35bc63e

Browse files
committed
Tests: add test for destructuring assignment
1 parent b3553be commit 35bc63e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

VariableAnalysis/Tests/CodeAnalysis/VariableAnalysisTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,16 @@ public function testIgnoreUnusedRegexpIgnoresUnusedVariables() {
508508
];
509509
$this->assertEquals($expectedWarnings, $lines);
510510
}
511+
512+
public function testAllowDestructuringAssignment() {
513+
$fixtureFile = $this->getFixture('DestructuringFixture.php');
514+
$phpcsFile = $this->prepareLocalFileForSniffs($this->getSniffFiles(), $fixtureFile);
515+
$phpcsFile->process();
516+
$lines = $this->getWarningLineNumbersFromFile($phpcsFile);
517+
$expectedWarnings = [
518+
4,
519+
12,
520+
];
521+
$this->assertEquals($expectedWarnings, $lines);
522+
}
511523
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
function function_with_destructuring_assignment() {
3+
[$a, $b] = [1, 2];
4+
[$c, $d] = [3, 4]; // unused
5+
echo $a;
6+
echo $b;
7+
echo $c;
8+
}
9+
10+
function function_with_destructuring_assignment_using_list() {
11+
list( $a, $b ) = [1, 2];
12+
list( $c, $d ) = [3, 4]; // unused
13+
echo $a;
14+
echo $b;
15+
echo $c;
16+
}

0 commit comments

Comments
 (0)