Skip to content

Commit 1821647

Browse files
committed
Unit test: fix tests failing
I'm not completely sure why, but when I tried to run the unit tests, most were failing. This minor tweak in how PHPCS is instantiated fixes it. It also removes the need for the `getSniffFiles()` method as there is only one sniff in this standard anyway.
1 parent 0b230c3 commit 1821647

File tree

2 files changed

+65
-66
lines changed

2 files changed

+65
-66
lines changed

VariableAnalysis/Tests/BaseTestCase.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +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-
}
16-
$ruleset->registerSniffs($sniffFiles, [], []);
17-
$ruleset->populateTokenListeners();
10+
const STANDARD_NAME = 'VariableAnalysis';
11+
const SNIFF_NAME = 'VariableAnalysis.CodeAnalysis.VariableAnalysis';
12+
13+
public function prepareLocalFileForSniffs($fixtureFile) {
14+
$config = new Config();
15+
$config->cache = false;
16+
$config->standards = [self::STANDARD_NAME];
17+
$config->sniffs = [self::SNIFF_NAME];
18+
$config->ignored = [];
19+
$ruleset = new Ruleset($config);
20+
1821
if (! file_exists($fixtureFile)) {
1922
throw new \Exception('Fixture file does not exist: ' . $fixtureFile);
2023
}
@@ -35,10 +38,6 @@ public function getErrorLineNumbersFromFile(LocalFile $phpcsFile) {
3538
return $this->getLineNumbersFromMessages($phpcsFile->getErrors());
3639
}
3740

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

0 commit comments

Comments
 (0)