-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f66cf5b
commit 991322c
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
tests/PHPStan/Command/ErrorFormatter/BaselinePhpErrorFormatterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Command\ErrorFormatter; | ||
|
||
use PHPStan\Analyser\Error; | ||
use PHPStan\Command\AnalysisResult; | ||
use PHPStan\File\ParentDirectoryRelativePathHelper; | ||
use PHPStan\Testing\ErrorFormatterTestCase; | ||
|
||
class BaselinePhpErrorFormatterTest extends ErrorFormatterTestCase | ||
{ | ||
|
||
public function dataFormatErrors(): iterable | ||
{ | ||
yield [ | ||
[ | ||
new Error( | ||
'Foo', | ||
__DIR__ . '/Foo.php', | ||
5, | ||
), | ||
new Error( | ||
'Foo', | ||
__DIR__ . '/Foo.php', | ||
5, | ||
), | ||
new Error( | ||
'Bar', | ||
__DIR__ . '/../Foo.php', | ||
5, | ||
), | ||
], | ||
<<<'PHP' | ||
<?php declare(strict_types = 1); | ||
$ignoreErrors = []; | ||
$ignoreErrors[] = [ | ||
'message' => '#^Bar$#', | ||
'count' => 1, | ||
'path' => __DIR__ . '/../Foo.php', | ||
]; | ||
$ignoreErrors[] = [ | ||
'message' => '#^Foo$#', | ||
'count' => 2, | ||
'path' => __DIR__ . '/Foo.php', | ||
]; | ||
return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; | ||
|
||
PHP, | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dataFormatErrors | ||
* @param list<Error> $errors | ||
*/ | ||
public function testFormatErrors(array $errors, string $expectedOutput): void | ||
{ | ||
$formatter = new BaselinePhpErrorFormatter(new ParentDirectoryRelativePathHelper(__DIR__)); | ||
$formatter->formatErrors( | ||
new AnalysisResult( | ||
$errors, | ||
[], | ||
[], | ||
[], | ||
[], | ||
false, | ||
null, | ||
true, | ||
0, | ||
), | ||
$this->getOutput(), | ||
); | ||
|
||
$this->assertSame($expectedOutput, $this->getOutputContent()); | ||
} | ||
|
||
} |