Skip to content

Commit eb1265f

Browse files
committed
Tests: add test for allowed unused import
1 parent bb4e927 commit eb1265f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

tests/Sniffs/Imports/RequireImportsAllowedPatternFixture.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace CAR_APP\Vehicles\Greatness;
55

66
use function whitelisted_function;
7+
use function unused_function;
78

89
class GreatClass {
910
private function activate() {

tests/Sniffs/Imports/RequireImportsSniffTest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ public function testRequireImportsSniffFindsUnimportedFunctionsWithNoConfig() {
5656
$phpcsFile->process();
5757
$lines = $helper->getWarningLineNumbersFromFile($phpcsFile);
5858
$expectedLines = [
59-
11,
59+
7,
6060
12,
61+
13,
6162
];
6263
$this->assertEquals($expectedLines, $lines);
6364
}
6465

65-
public function testRequireImportsSniffIgnoresAllowedImports() {
66+
public function testRequireImportsSniffIgnoresWhitelistedUnimportedSymbols() {
6667
$fixtureFile = __DIR__ . '/RequireImportsAllowedPatternFixture.php';
6768
$sniffFile = __DIR__ . '/../../../ImportDetection/Sniffs/Imports/RequireImportsSniff.php';
6869
$helper = new SniffTestHelper();
@@ -74,7 +75,23 @@ public function testRequireImportsSniffIgnoresAllowedImports() {
7475
);
7576
$phpcsFile->process();
7677
$lines = $helper->getWarningLineNumbersFromFile($phpcsFile);
77-
$expectedLines = [ 12 ];
78+
$expectedLines = [ 7, 13 ];
79+
$this->assertEquals($expectedLines, $lines);
80+
}
81+
82+
public function testRequireImportsSniffIgnoresWhitelistedUnusedImports() {
83+
$fixtureFile = __DIR__ . '/RequireImportsAllowedPatternFixture.php';
84+
$sniffFile = __DIR__ . '/../../../ImportDetection/Sniffs/Imports/RequireImportsSniff.php';
85+
$helper = new SniffTestHelper();
86+
$phpcsFile = $helper->prepareLocalFileForSniffs($sniffFile, $fixtureFile);
87+
$phpcsFile->ruleset->setSniffProperty(
88+
'ImportDetection\Sniffs\Imports\RequireImportsSniff',
89+
'ignoreUnimportedSymbols',
90+
'/^(unused_function)$/'
91+
);
92+
$phpcsFile->process();
93+
$lines = $helper->getWarningLineNumbersFromFile($phpcsFile);
94+
$expectedLines = [ 12, 13 ];
7895
$this->assertEquals($expectedLines, $lines);
7996
}
8097

0 commit comments

Comments
 (0)