Skip to content

Commit 4460411

Browse files
jrfnlsirbrillig
authored andcommitted
Tests: simplify the PHPCS setup method [1] (#115)
- Remove the `$sniffFiles` parameter which doesn't change between calls to the method anyway and replace it with a class constant and a call to `realpath()` within the function. - Remove the `getSniffFiles()` method which is now no longer needed. - Adjust all calls to the `prepareLocalFileForSniffs()` method to remove the parameter.
1 parent 4dd368f commit 4460411

File tree

2 files changed

+65
-64
lines changed

2 files changed

+65
-64
lines changed

VariableAnalysis/Tests/BaseTestCase.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
use PHP_CodeSniffer\Config;
88

99
class BaseTestCase extends TestCase {
10-
public function prepareLocalFileForSniffs($sniffFiles, $fixtureFile) {
11-
$config = new Config(['--standard=VariableAnalysis']);
12-
$ruleset = new Ruleset($config);
13-
if (! is_array($sniffFiles)) {
14-
$sniffFiles = [$sniffFiles];
15-
}
10+
const STANDARD_NAME = 'VariableAnalysis';
11+
const SNIFF_FILE = __DIR__ . '/../Sniffs/CodeAnalysis/VariableAnalysisSniff.php';
12+
13+
public function prepareLocalFileForSniffs($fixtureFile) {
14+
$config = new Config();
15+
$config->cache = false;
16+
$config->standards = [self::STANDARD_NAME];
17+
$config->ignored = [];
18+
19+
$sniffFiles = [realpath(self::SNIFF_FILE)];
20+
$ruleset = new Ruleset($config);
1621
$ruleset->registerSniffs($sniffFiles, [], []);
1722
$ruleset->populateTokenListeners();
1823
if (! file_exists($fixtureFile)) {
@@ -35,10 +40,6 @@ public function getErrorLineNumbersFromFile(LocalFile $phpcsFile) {
3540
return $this->getLineNumbersFromMessages($phpcsFile->getErrors());
3641
}
3742

38-
public function getSniffFiles() {
39-
return [realpath(__DIR__ . '/../../VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php')];
40-
}
41-
4243
public function getFixture($fixtureFilename) {
4344
return realpath(__DIR__ . '/CodeAnalysis/fixtures/' . $fixtureFilename);
4445
}

0 commit comments

Comments
 (0)