diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d5f101..37a5a194 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), For a full diff see [`2.20.0...main`][2.20.0...main]. +### Changed + +- Started showing output when no tests could be detected with a duration exceeding the maximum duration ([#714]), by [@localheinz] + ## [`2.20.0`][2.20.0] For a full diff see [`2.19.1...2.20.0`][2.19.1...2.20.0]. @@ -423,6 +427,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#651]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/651 [#664]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/664 [#704]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/704 +[#714]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/714 [@dantleech]: https://github.com/dantleech [@HypeMC]: https://github.com/HypeMC diff --git a/src/Reporter/DefaultReporter.php b/src/Reporter/DefaultReporter.php index 2c3f694b..330a7ae0 100644 --- a/src/Reporter/DefaultReporter.php +++ b/src/Reporter/DefaultReporter.php @@ -43,10 +43,6 @@ public function __construct( public function report(SlowTestList $slowTestList): string { - if ($slowTestList->isEmpty()) { - return ''; - } - return \implode("\n", \iterator_to_array($this->lines($slowTestList))); } @@ -57,6 +53,12 @@ private function lines(SlowTestList $slowTestList): \Generator { $slowTestCount = $slowTestList->count(); + if ($slowTestCount->equals(Count::fromInt(0))) { + yield 'Could not detect any tests where the duration exceeded the maximum duration.'; + + return; + } + if ($slowTestCount->equals(Count::fromInt(1))) { yield 'Detected 1 test where the duration exceeded the maximum duration.'; } else { diff --git a/test/Unit/Reporter/DefaultReporterTest.php b/test/Unit/Reporter/DefaultReporterTest.php index 6e6d29eb..6ad489c7 100644 --- a/test/Unit/Reporter/DefaultReporterTest.php +++ b/test/Unit/Reporter/DefaultReporterTest.php @@ -57,7 +57,7 @@ public function testReportReturnsEmptyStringWhenSlowTestListIsEmpty() $report = $reporter->report($slowTestList); - self::assertSame('', $report); + self::assertSame('Could not detect any tests where the duration exceeded the maximum duration.', $report); } /**