Skip to content

Commit

Permalink
Merge pull request #485 from qossmic/report-skipped-table-output-form…
Browse files Browse the repository at this point in the history
…atter

Add support for report skipped option in TableOutputFormatter
  • Loading branch information
Simon Mönch committed Feb 8, 2021
2 parents 20db2a4 + 3813a8c commit 707f136
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/OutputFormatter/TableOutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ public function finish(
): void {
$groupedRules = [];
$reportUncovered = $outputFormatterInput->getOptionAsBoolean(AnalyzeCommand::OPTION_REPORT_UNCOVERED);
$reportSkipped = $outputFormatterInput->getOptionAsBoolean(AnalyzeCommand::OPTION_REPORT_SKIPPED);

foreach ($context->rules() as $rule) {
if ($rule instanceof Allowed) {
continue;
}

if ($rule instanceof Violation || $rule instanceof SkippedViolation) {
if ($rule instanceof Violation || ($reportSkipped && $rule instanceof SkippedViolation)) {
$groupedRules[$rule->getLayerA()][] = $rule;
} elseif ($reportUncovered && $rule instanceof Uncovered) {
$groupedRules[$rule->getLayer()][] = $rule;
Expand Down
61 changes: 55 additions & 6 deletions tests/OutputFormatter/TableOutputFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function basicDataProvider(): iterable
',
];

yield [
yield 'skipped violations' => [
[
new SkippedViolation(
new Dependency($originalA, $originalB, FileOccurrence::fromFilepath('originalA.php', 12)),
Expand Down Expand Up @@ -168,15 +168,39 @@ public function basicDataProvider(): iterable
',
];

yield [
yield 'skipped violations without reporting' => [
[
new SkippedViolation(
new Dependency($originalA, $originalB, FileOccurrence::fromFilepath('originalA.php', 12)),
'LayerA',
'LayerB'
),
],
[],
'
-------------------- -----
Report
-------------------- -----
Violations 0
Skipped violations 1
Uncovered 0
Allowed 0
-------------------- -----
',
'reportUncovered' => true,
'reportSkipped' => false,
];

yield 'uncovered' => [
'rules' => [
new Uncovered(
new Dependency($originalA, $originalB, FileOccurrence::fromFilepath('originalA.php', 12)),
'LayerA'
),
],
[],
' ----------- -------------------------------------------------
'errors' => [],
'expectedOutput' => ' ----------- -------------------------------------------------
Reason LayerA
----------- -------------------------------------------------
Uncovered OriginalA has uncovered dependency on OriginalB
Expand All @@ -196,6 +220,28 @@ public function basicDataProvider(): iterable
',
];

yield 'uncovered without reporting' => [
'rules' => [
new Uncovered(
new Dependency($originalA, $originalB, FileOccurrence::fromFilepath('originalA.php', 12)),
'LayerA'
),
],
'errors' => [],
'expectedOutput' => '
-------------------- -----
Report
-------------------- -----
Violations 0
Skipped violations 0
Uncovered 1
Allowed 0
-------------------- -----
',
'reportUncovered' => false,
];

yield 'an error occurred' => [
[],
[new Error('an error occurred')],
Expand All @@ -222,7 +268,7 @@ public function basicDataProvider(): iterable
/**
* @dataProvider basicDataProvider
*/
public function testBasic(array $rules, array $errors, string $expectedOutput): void
public function testBasic(array $rules, array $errors, string $expectedOutput, bool $reportUncovered = true, bool $reportSkipped = true): void
{
$bufferedOutput = new BufferedOutput();
$output = new SymfonyOutput(
Expand All @@ -234,7 +280,10 @@ public function testBasic(array $rules, array $errors, string $expectedOutput):
$formatter->finish(
new Context($rules, $errors),
$output,
new OutputFormatterInput([AnalyzeCommand::OPTION_REPORT_UNCOVERED => true])
new OutputFormatterInput([
AnalyzeCommand::OPTION_REPORT_UNCOVERED => $reportUncovered,
AnalyzeCommand::OPTION_REPORT_SKIPPED => $reportSkipped,
])
);

static::assertEquals($expectedOutput, $bufferedOutput->fetch());
Expand Down

0 comments on commit 707f136

Please sign in to comment.