-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
7e77c2b
commit 0ea70fd
Showing
6 changed files
with
125 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TwigCsFixer\Tests\Report\Formatter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SplFileInfo; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use TwigCsFixer\Report\Report; | ||
use TwigCsFixer\Report\Reporter\CheckstyleReporter; | ||
use TwigCsFixer\Report\SniffViolation; | ||
|
||
final class CheckstyleReporterTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider displayDataProvider | ||
*/ | ||
public function testDisplayErrors(string $expected, ?string $level): void | ||
{ | ||
$textFormatter = new CheckstyleReporter(); | ||
|
||
$file = __DIR__.'/Fixtures/file.twig'; | ||
$report = new Report([new SplFileInfo($file)]); | ||
|
||
$violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeSniff'); | ||
$report->addMessage($violation0); | ||
$violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningSniff'); | ||
$report->addMessage($violation1); | ||
$violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorSniff'); | ||
$report->addMessage($violation2); | ||
$violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); | ||
$report->addMessage($violation3); | ||
|
||
$output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); | ||
$textFormatter->display($output, $report, $level); | ||
|
||
$text = $output->fetch(); | ||
static::assertStringContainsString($expected, $text); | ||
} | ||
|
||
/** | ||
* @return iterable<array-key, array{string, string|null}> | ||
*/ | ||
public static function displayDataProvider(): iterable | ||
{ | ||
yield [ | ||
sprintf( | ||
<<<EOD | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<checkstyle> | ||
<file name="%s/Fixtures/file.twig"> | ||
<error line="1" column="11" severity="notice" message="Notice" source="NoticeSniff"/> | ||
<error line="2" column="22" severity="warning" message="Warning" source="WarningSniff"/> | ||
<error line="3" column="33" severity="error" message="Error" source="ErrorSniff"/> | ||
<error severity="fatal" message="Fatal"/> | ||
</file> | ||
</checkstyle> | ||
EOD, | ||
__DIR__ | ||
), | ||
null, | ||
]; | ||
|
||
yield [ | ||
sprintf( | ||
<<<EOD | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<checkstyle> | ||
<file name="%s/Fixtures/file.twig"> | ||
<error line="3" column="33" severity="error" message="Error" source="ErrorSniff"/> | ||
<error severity="fatal" message="Fatal"/> | ||
</file> | ||
</checkstyle> | ||
EOD, | ||
__DIR__ | ||
), | ||
Report::MESSAGE_TYPE_ERROR, | ||
]; | ||
} | ||
} |
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