Skip to content

Commit

Permalink
Print number of issues ignored by baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 14, 2023
1 parent 397bfc9 commit 4449996
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/Runner/TestResult/Collector.php
Expand Up @@ -59,6 +59,11 @@ final class Collector
private bool $prepared = false;
private bool $currentTestSuiteForTestClassFailed = false;

/**
* @psalm-var non-negative-int
*/
private int $numberOfIssuesIgnoredByBaseline = 0;

/**
* @psalm-var list<BeforeFirstTestMethodErrored|Errored>
*/
Expand Down Expand Up @@ -209,6 +214,7 @@ public function result(): TestResult
array_values($this->phpDeprecations),
array_values($this->phpNotices),
array_values($this->phpWarnings),
$this->numberOfIssuesIgnoredByBaseline,
);
}

Expand Down Expand Up @@ -343,6 +349,8 @@ public function testConsideredRisky(ConsideredRisky $event): void
public function testTriggeredDeprecation(DeprecationTriggered $event): void
{
if ($event->ignoredByBaseline()) {
$this->numberOfIssuesIgnoredByBaseline++;

return;
}

Expand Down Expand Up @@ -373,6 +381,8 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): void
{
if ($event->ignoredByBaseline()) {
$this->numberOfIssuesIgnoredByBaseline++;

return;
}

Expand Down Expand Up @@ -434,6 +444,8 @@ public function testTriggeredError(ErrorTriggered $event): void
public function testTriggeredNotice(NoticeTriggered $event): void
{
if ($event->ignoredByBaseline()) {
$this->numberOfIssuesIgnoredByBaseline++;

return;
}

Expand Down Expand Up @@ -464,6 +476,8 @@ public function testTriggeredNotice(NoticeTriggered $event): void
public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
{
if ($event->ignoredByBaseline()) {
$this->numberOfIssuesIgnoredByBaseline++;

return;
}

Expand Down Expand Up @@ -494,6 +508,8 @@ public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
public function testTriggeredWarning(WarningTriggered $event): void
{
if ($event->ignoredByBaseline()) {
$this->numberOfIssuesIgnoredByBaseline++;

return;
}

Expand Down Expand Up @@ -524,6 +540,8 @@ public function testTriggeredWarning(WarningTriggered $event): void
public function testTriggeredPhpWarning(PhpWarningTriggered $event): void
{
if ($event->ignoredByBaseline()) {
$this->numberOfIssuesIgnoredByBaseline++;

return;
}

Expand Down
22 changes: 21 additions & 1 deletion src/Runner/TestResult/TestResult.php
Expand Up @@ -123,6 +123,11 @@ final class TestResult
*/
private readonly array $phpWarnings;

/**
* @psalm-var non-negative-int
*/
private readonly int $numberOfIssuesIgnoredByBaseline;

/**
* @psalm-param list<BeforeFirstTestMethodErrored|Errored> $testErroredEvents
* @psalm-param list<Failed> $testFailedEvents
Expand All @@ -142,8 +147,9 @@ final class TestResult
* @psalm-param list<Issue> $phpDeprecations
* @psalm-param list<Issue> $phpNotices
* @psalm-param list<Issue> $phpWarnings
* @psalm-param non-negative-int $numberOfIssuesIgnoredByBaseline
*/
public function __construct(int $numberOfTests, int $numberOfTestsRun, int $numberOfAssertions, array $testErroredEvents, array $testFailedEvents, array $testConsideredRiskyEvents, array $testSuiteSkippedEvents, array $testSkippedEvents, array $testMarkedIncompleteEvents, array $testTriggeredPhpunitDeprecationEvents, array $testTriggeredPhpunitErrorEvents, array $testTriggeredPhpunitWarningEvents, array $testRunnerTriggeredDeprecationEvents, array $testRunnerTriggeredWarningEvents, array $errors, array $deprecations, array $notices, array $warnings, array $phpDeprecations, array $phpNotices, array $phpWarnings)
public function __construct(int $numberOfTests, int $numberOfTestsRun, int $numberOfAssertions, array $testErroredEvents, array $testFailedEvents, array $testConsideredRiskyEvents, array $testSuiteSkippedEvents, array $testSkippedEvents, array $testMarkedIncompleteEvents, array $testTriggeredPhpunitDeprecationEvents, array $testTriggeredPhpunitErrorEvents, array $testTriggeredPhpunitWarningEvents, array $testRunnerTriggeredDeprecationEvents, array $testRunnerTriggeredWarningEvents, array $errors, array $deprecations, array $notices, array $warnings, array $phpDeprecations, array $phpNotices, array $phpWarnings, int $numberOfIssuesIgnoredByBaseline)
{
$this->numberOfTests = $numberOfTests;
$this->numberOfTestsRun = $numberOfTestsRun;
Expand All @@ -166,6 +172,7 @@ public function __construct(int $numberOfTests, int $numberOfTestsRun, int $numb
$this->phpDeprecations = $phpDeprecations;
$this->phpNotices = $phpNotices;
$this->phpWarnings = $phpWarnings;
$this->numberOfIssuesIgnoredByBaseline = $numberOfIssuesIgnoredByBaseline;
}

public function numberOfTestsRun(): int
Expand Down Expand Up @@ -529,4 +536,17 @@ public function hasSkippedTests(): bool
{
return !empty($this->testSkippedEvents);
}

public function hasIssuesIgnoredByBaseline(): bool
{
return $this->numberOfIssuesIgnoredByBaseline > 0;
}

/**
* @psalm-return non-negative-int
*/
public function numberOfIssuesIgnoredByBaseline(): int
{
return $this->numberOfIssuesIgnoredByBaseline;
}
}
20 changes: 20 additions & 0 deletions src/TextUI/Output/SummaryPrinter.php
Expand Up @@ -53,6 +53,8 @@ public function print(TestResult $result): void
),
);

$this->printNumberOfIssuesIgnoredByBaseline($result);

return;
}

Expand Down Expand Up @@ -114,6 +116,8 @@ public function print(TestResult $result): void
$this->printCountString($result->numberOfTestMarkedIncompleteEvents(), 'Incomplete', $color);
$this->printCountString($result->numberOfTestsWithTestConsideredRiskyEvents(), 'Risky', $color);
$this->printWithColor($color, '.');

$this->printNumberOfIssuesIgnoredByBaseline($result);
}

private function printCountString(int $count, string $name, string $color, bool $always = false): void
Expand Down Expand Up @@ -146,4 +150,20 @@ private function printWithColor(string $color, string $buffer, bool $lf = true):
$this->printer->print(PHP_EOL);
}
}

private function printNumberOfIssuesIgnoredByBaseline(TestResult $result): void
{
if ($result->hasIssuesIgnoredByBaseline()) {
$this->printer->print(
sprintf(
'%s%d issue%s %s ignored by baseline.%s',
PHP_EOL,
$result->numberOfIssuesIgnoredByBaseline(),
$result->numberOfIssuesIgnoredByBaseline() > 1 ? 's' : '',
$result->numberOfIssuesIgnoredByBaseline() > 1 ? 'were' : 'was',
PHP_EOL,
),
);
}
}
}
2 changes: 2 additions & 0 deletions tests/end-to-end/baseline/use-baseline.phpt
Expand Up @@ -20,3 +20,5 @@ Configuration: %s
Time: %s, Memory: %s

OK (1 test, 1 assertion)

1 issue was ignored by baseline.
16 changes: 15 additions & 1 deletion tests/unit/TextUI/Output/Default/ResultPrinterTest.php
Expand Up @@ -344,6 +344,19 @@ public static function provider(): array
),
],

'successful test that triggers baseline-ignored issue' => [
__DIR__ . '/expectations/successful_test_with_baseline_ignored_issue.txt',
self::createTestResult(
numberOfIssuesIgnoredByBaseline: 1,
),
],

'successful test that triggers baseline-ignored issues' => [
__DIR__ . '/expectations/successful_test_with_baseline_ignored_issues.txt',
self::createTestResult(
numberOfIssuesIgnoredByBaseline: 2,
),
],
];
}

Expand Down Expand Up @@ -428,7 +441,7 @@ public function buffer(): string
* @psalm-param list<TestRunnerDeprecationTriggered> $testRunnerTriggeredDeprecationEvents
* @psalm-param list<TestRunnerWarningTriggered> $testRunnerTriggeredWarningEvents
*/
private static function createTestResult(int $numberOfTests = 1, int $numberOfTestsRun = 1, int $numberOfAssertions = 1, array $testErroredEvents = [], array $testFailedEvents = [], array $testConsideredRiskyEvents = [], array $testSuiteSkippedEvents = [], array $testSkippedEvents = [], array $testMarkedIncompleteEvents = [], array $deprecations = [], array $phpDeprecations = [], array $testTriggeredPhpunitDeprecationEvents = [], array $errors = [], array $notices = [], array $phpNotices = [], array $warnings = [], array $phpWarnings = [], array $testTriggeredPhpunitErrorEvents = [], array $testTriggeredPhpunitWarningEvents = [], array $testRunnerTriggeredDeprecationEvents = [], array $testRunnerTriggeredWarningEvents = []): TestResult
private static function createTestResult(int $numberOfTests = 1, int $numberOfTestsRun = 1, int $numberOfAssertions = 1, array $testErroredEvents = [], array $testFailedEvents = [], array $testConsideredRiskyEvents = [], array $testSuiteSkippedEvents = [], array $testSkippedEvents = [], array $testMarkedIncompleteEvents = [], array $deprecations = [], array $phpDeprecations = [], array $testTriggeredPhpunitDeprecationEvents = [], array $errors = [], array $notices = [], array $phpNotices = [], array $warnings = [], array $phpWarnings = [], array $testTriggeredPhpunitErrorEvents = [], array $testTriggeredPhpunitWarningEvents = [], array $testRunnerTriggeredDeprecationEvents = [], array $testRunnerTriggeredWarningEvents = [], int $numberOfIssuesIgnoredByBaseline = 0): TestResult
{
return new TestResult(
$numberOfTests,
Expand All @@ -452,6 +465,7 @@ private static function createTestResult(int $numberOfTests = 1, int $numberOfTe
$phpDeprecations,
$phpNotices,
$phpWarnings,
$numberOfIssuesIgnoredByBaseline,
);
}

Expand Down
@@ -0,0 +1,3 @@
OK (1 test, 1 assertion)

1 issue was ignored by baseline.
@@ -0,0 +1,3 @@
OK (1 test, 1 assertion)

2 issues were ignored by baseline.

0 comments on commit 4449996

Please sign in to comment.