Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Account for a single slow test in report #34

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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