Skip to content

Commit

Permalink
Fix: Account for a single slow test in report
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Jan 25, 2021
1 parent 3b019a0 commit 1713679
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Reporter/DefaultReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ private function header(SlowTest ...$slowTests): string

$formattedMaximumDuration = $this->durationFormatter->format($this->maximumDuration);

if (1 === $count) {
return <<<TXT
Detected {$count} test that took longer than {$formattedMaximumDuration}.
TXT;
}

return <<<TXT
Detected {$count} tests that took longer than {$formattedMaximumDuration}.
Expand Down
44 changes: 43 additions & 1 deletion test/Unit/Reporter/DefaultReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,49 @@ public function testReportReturnsEmptyStringWhenNoSlowTestsHaveBeenSpecified():
self::assertSame('', $report);
}

public function testReportReturnsReportWhenTheNumberOfSlowTestsIsSmallerThanTheMaximumCount(): void
public function testReportReturnsReportWhenTheNumberOfSlowTestsIsSmallerThanTheMaximumCountAndLessThanOne(): void
{
$slowTests = [
SlowTest::fromTestAndDuration(
new Event\Code\Test(
Example\SleeperTest::class,
'foo',
'foo with data set #123',
),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
7,
890_123_456
)
),
];

$durationFormatter = new ToMillisecondsDurationFormatter();

$maximumDuration = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
0,
100_000_000
);

$maximumNumber = \count($slowTests);

$reporter = new DefaultReporter(
$durationFormatter,
$maximumDuration,
$maximumNumber
);

$report = $reporter->report(...$slowTests);

$expected = <<<'TXT'
Detected 1 test that took longer than 100 ms.
7,890 ms: Ergebnis\PHPUnit\SlowTestDetector\Test\Example\SleeperTest::foo with data set #123
TXT;

self::assertSame($expected, $report);
}

public function testReportReturnsReportWhenTheNumberOfSlowTestsIsSmallerThanTheMaximumCountAndGreaterThanOne(): void
{
$faker = self::faker();

Expand Down

0 comments on commit 1713679

Please sign in to comment.