Skip to content

Commit f2f7998

Browse files
authored
Merge pull request #14 from sirbrillig/add/less-automated-tests
Alter tests to run without AbstractSniffUnitTest
2 parents baaa443 + b266b49 commit f2f7998

23 files changed

+979
-761
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,10 @@ This was forked from the excellent work in https://github.com/illusori/PHP_Codes
6666
## Contributing
6767

6868
Please open issues or PRs on this repository.
69+
70+
To run tests, make sure composer is installed, then run:
71+
72+
```
73+
composer install # you only need to do this once
74+
composer test
75+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace VariableAnalysis\Tests;
3+
4+
use PHPUnit\Framework\TestCase;
5+
use PHP_CodeSniffer\Files\LocalFile;
6+
use PHP_CodeSniffer\Ruleset;
7+
use PHP_CodeSniffer\Config;
8+
9+
class BaseTestCase extends TestCase {
10+
public function prepareLocalFileForSniffs($sniffFiles, string $fixtureFile): LocalFile {
11+
$config = new Config();
12+
$ruleset = new Ruleset($config);
13+
if (! is_array($sniffFiles)) {
14+
$sniffFiles = [$sniffFiles];
15+
}
16+
$ruleset->registerSniffs($sniffFiles, [], []);
17+
$ruleset->populateTokenListeners();
18+
return new LocalFile($fixtureFile, $ruleset, $config);
19+
}
20+
21+
public function getLineNumbersFromMessages(array $messages): array {
22+
return array_keys($messages);
23+
}
24+
25+
public function getWarningLineNumbersFromFile(LocalFile $phpcsFile): array {
26+
return $this->getLineNumbersFromMessages($phpcsFile->getWarnings());
27+
}
28+
29+
public function getErrorLineNumbersFromFile(LocalFile $phpcsFile): array {
30+
return $this->getLineNumbersFromMessages($phpcsFile->getErrors());
31+
}
32+
33+
public function getSniffFiles(): array {
34+
return [__DIR__ . '/../../VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php'];
35+
}
36+
}

0 commit comments

Comments
 (0)