From 8aceb52af15d392c10a8dd082008c9242e94e93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 12 Feb 2023 13:29:59 +0100 Subject: [PATCH] Enhancement: Render slow tests as ordered list --- CHANGELOG.md | 5 +++++ README.md | 20 +++++++++---------- src/Reporter/DefaultReporter.php | 14 ++++++++++--- test/EndToEnd/Default/test.phpt | 20 +++++++++---------- test/EndToEnd/MaximumCount/Five/test.phpt | 10 +++++----- test/EndToEnd/MaximumDuration/Fifty/test.phpt | 14 ++++++------- 6 files changed, 48 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b398e396..f1690ed0 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.0.0...main`][2.0.0...main]. +### Changed + +- Started rendering slow tests as ordered list ([#224]), by [@localheinz] + ## [`2.0.0`][2.0.0] For a full diff see [`1.0.0...2.0.0`][1.0.0...2.0.0]. @@ -96,5 +100,6 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#220]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/220 [#221]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/221 [#222]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/222 +[#224]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/224 [@localheinz]: https://github.com/localheinz diff --git a/README.md b/README.md index 1bec7402..54499de4 100644 --- a/README.md +++ b/README.md @@ -129,16 +129,16 @@ Random Seed: 1676103726 Detected 11 tests that took longer than expected. -1.605 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#9 -1.505 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#8 -1.401 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#7 -1.301 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#6 -1.200 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#5 -1.105 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#4 -1.000 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3 -0.903 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2 -0.802 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1 -0.703 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#0 + 1. 1.604 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#9 + 2. 1.505 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#8 + 3. 1.403 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#7 + 4. 1.303 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#6 + 5. 1.205 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#5 + 6. 1.103 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#4 + 7. 1.005 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3 + 8. 0.905 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2 + 9. 0.805 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1 +10. 0.705 (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#0 There is 1 additional slow test that is not listed here. diff --git a/src/Reporter/DefaultReporter.php b/src/Reporter/DefaultReporter.php index 3dfb1bf6..07810108 100644 --- a/src/Reporter/DefaultReporter.php +++ b/src/Reporter/DefaultReporter.php @@ -110,10 +110,18 @@ static function (Event\Telemetry\Duration $maximumDuration, SlowTest $slowTest): $durationFormatter = $this->durationFormatter; + $numberWidth = \strlen((string) \count($slowTestsToReport)); $durationWidth = \strlen($durationFormatter->format($slowestTest->duration())); $maximumDurationWidth = \strlen($durationFormatter->format($longestMaximumDuration)); - $items = \array_map(static function (SlowTest $slowTest) use ($durationFormatter, $durationWidth, $maximumDurationWidth): string { + $items = \array_map(static function (int $index, SlowTest $slowTest) use ($numberWidth, $durationFormatter, $durationWidth, $maximumDurationWidth): string { + $formattedNumber = \str_pad( + (string) ($index + 1), + $numberWidth, + ' ', + \STR_PAD_LEFT, + ); + $formattedDuration = \str_pad( $durationFormatter->format($slowTest->duration()), $durationWidth, @@ -134,9 +142,9 @@ static function (Event\Telemetry\Duration $maximumDuration, SlowTest $slowTest): $testName = $slowTest->test()->id(); return <<