Skip to content

Commit

Permalink
Test BaselinePhpErrorFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 16, 2023
1 parent f66cf5b commit 991322c
Showing 1 changed file with 79 additions and 0 deletions.
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());
}

}

0 comments on commit 991322c

Please sign in to comment.