-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractRuleTestCase.php
43 lines (35 loc) · 1.2 KB
/
AbstractRuleTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
declare(strict_types=1);
namespace DaveLiddament\PhpstanRuleTestHelper;
use DaveLiddament\PhpstanRuleTestHelper\Internal\FixtureFileReader;
use DaveLiddament\PhpstanRuleTestHelper\Internal\InvalidFixtureFile;
use PHPStan\Testing\RuleTestCase;
/**
* @template TRule of \PHPStan\Rules\Rule
*
* @extends RuleTestCase<TRule>
*/
abstract class AbstractRuleTestCase extends RuleTestCase
{
/** @throws InvalidFixtureFile */
final protected function assertIssuesReported(string ...$fixtureFiles): void
{
$fixtureFileReader = new FixtureFileReader();
$errorFormatter = $this->getErrorFormatter();
if (is_string($errorFormatter)) {
$errorFormatter = new StringErrorMessageConverter($errorFormatter);
}
$expectedErrors = [];
foreach ($fixtureFiles as $fixture) {
$expectedErrors = array_merge(
$expectedErrors,
$fixtureFileReader->getExpectedErrors($fixture, $errorFormatter),
);
}
$this->analyse($fixtureFiles, $expectedErrors);
}
protected function getErrorFormatter(): ErrorMessageFormatter|string
{
return new DefaultErrorMessageFormatter();
}
}