From 6444621d4f9f7633b24344f9cdcbac0cfb952c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 23 Dec 2023 22:11:35 +0100 Subject: [PATCH] Fix: Do not report maximum duration for slow tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andreas Möller Co-authored-by: Michael Voříšek --- CHANGELOG.md | 5 ++ README.md | 20 +++--- src/Extension.php | 2 - src/Reporter/DefaultReporter.php | 31 +--------- .../Configuration/Defaults/test.phpt | 20 +++--- .../Configuration/MaximumCount/test.phpt | 6 +- .../Configuration/MaximumDuration/test.phpt | 20 +++--- .../Version07/TestCase/Bare/test.phpt | 4 +- .../Version07/TestCase/Combination/test.phpt | 6 +- .../TestCase/WithAfterAnnotation/test.phpt | 6 +- .../WithAfterClassAnnotation/test.phpt | 4 +- .../WithAssertPostConditions/test.phpt | 6 +- .../WithAssertPreConditions/test.phpt | 6 +- .../TestCase/WithBeforeAnnotation/test.phpt | 6 +- .../WithBeforeClassAnnotation/test.phpt | 4 +- .../TestCase/WithDataProvider/test.phpt | 4 +- .../Version07/TestCase/WithSetUp/test.phpt | 6 +- .../TestCase/WithSetUpBeforeClass/test.phpt | 4 +- .../Version07/TestCase/WithTearDown/test.phpt | 6 +- .../TestCase/WithTearDownAfterClass/test.phpt | 4 +- .../test.phpt | 2 +- .../WithMaximumDurationAnnotation/test.phpt | 4 +- .../test.phpt | 8 +-- .../test.phpt | 2 +- .../WithSlowThresholdAnnotation/test.phpt | 4 +- .../Configuration/Defaults/test.phpt | 20 +++--- .../Configuration/MaximumCount/test.phpt | 6 +- .../Configuration/MaximumDuration/test.phpt | 20 +++--- .../Version08/TestCase/Bare/test.phpt | 4 +- .../Version08/TestCase/Combination/test.phpt | 6 +- .../TestCase/WithAfterAnnotation/test.phpt | 6 +- .../WithAfterClassAnnotation/test.phpt | 4 +- .../WithAssertPostConditions/test.phpt | 6 +- .../WithAssertPreConditions/test.phpt | 6 +- .../TestCase/WithBeforeAnnotation/test.phpt | 6 +- .../WithBeforeClassAnnotation/test.phpt | 4 +- .../TestCase/WithDataProvider/test.phpt | 4 +- .../Version08/TestCase/WithSetUp/test.phpt | 6 +- .../TestCase/WithSetUpBeforeClass/test.phpt | 4 +- .../Version08/TestCase/WithTearDown/test.phpt | 6 +- .../TestCase/WithTearDownAfterClass/test.phpt | 4 +- .../test.phpt | 2 +- .../WithMaximumDurationAnnotation/test.phpt | 4 +- .../test.phpt | 8 +-- .../test.phpt | 2 +- .../WithSlowThresholdAnnotation/test.phpt | 4 +- .../Configuration/Defaults/test.phpt | 20 +++--- .../Configuration/MaximumCount/test.phpt | 6 +- .../Configuration/MaximumDuration/test.phpt | 20 +++--- .../Version09/TestCase/Bare/test.phpt | 4 +- .../Version09/TestCase/Combination/test.phpt | 6 +- .../TestCase/WithAfterAnnotation/test.phpt | 6 +- .../WithAfterClassAnnotation/test.phpt | 4 +- .../WithAssertPostConditions/test.phpt | 6 +- .../WithAssertPreConditions/test.phpt | 6 +- .../TestCase/WithBeforeAnnotation/test.phpt | 6 +- .../WithBeforeClassAnnotation/test.phpt | 4 +- .../TestCase/WithDataProvider/test.phpt | 4 +- .../Version09/TestCase/WithSetUp/test.phpt | 6 +- .../TestCase/WithSetUpBeforeClass/test.phpt | 4 +- .../Version09/TestCase/WithTearDown/test.phpt | 6 +- .../TestCase/WithTearDownAfterClass/test.phpt | 4 +- .../test.phpt | 2 +- .../WithMaximumDurationAnnotation/test.phpt | 4 +- .../test.phpt | 8 +-- .../test.phpt | 2 +- .../WithSlowThresholdAnnotation/test.phpt | 4 +- .../Configuration/Defaults/test.phpt | 20 +++--- .../Configuration/MaximumCount/test.phpt | 6 +- .../Configuration/MaximumDuration/test.phpt | 20 +++--- .../Version10/TestCase/Bare/test.phpt | 4 +- .../Version10/TestCase/Combination/test.phpt | 6 +- .../TestCase/WithAfterAnnotation/test.phpt | 6 +- .../TestCase/WithAfterAttribute/test.phpt | 6 +- .../WithAfterClassAnnotation/test.phpt | 4 +- .../WithAfterClassAttribute/test.phpt | 4 +- .../WithAssertPostConditions/test.phpt | 6 +- .../WithAssertPreConditions/test.phpt | 6 +- .../TestCase/WithBeforeAnnotation/test.phpt | 6 +- .../TestCase/WithBeforeAttribute/test.phpt | 6 +- .../WithBeforeClassAnnotation/test.phpt | 4 +- .../WithBeforeClassAttribute/test.phpt | 4 +- .../TestCase/WithDataProvider/test.phpt | 4 +- .../Version10/TestCase/WithSetUp/test.phpt | 6 +- .../TestCase/WithSetUpBeforeClass/test.phpt | 4 +- .../Version10/TestCase/WithTearDown/test.phpt | 6 +- .../TestCase/WithTearDownAfterClass/test.phpt | 4 +- .../test.phpt | 2 +- .../WithMaximumDurationAnnotation/test.phpt | 4 +- .../WithMaximumDurationAttribute/test.phpt | 2 +- .../test.phpt | 8 +-- .../test.phpt | 8 +-- .../test.phpt | 2 +- .../WithSlowThresholdAnnotation/test.phpt | 4 +- .../Configuration/Defaults/test.phpt | 20 +++--- .../Configuration/MaximumCount/test.phpt | 6 +- .../Configuration/MaximumDuration/test.phpt | 20 +++--- .../Version11/TestCase/Bare/test.phpt | 4 +- .../Version11/TestCase/Combination/test.phpt | 6 +- .../TestCase/WithAfterAttribute/test.phpt | 6 +- .../WithAfterClassAttribute/test.phpt | 4 +- .../WithAssertPostConditions/test.phpt | 6 +- .../WithAssertPreConditions/test.phpt | 6 +- .../TestCase/WithBeforeAttribute/test.phpt | 6 +- .../WithBeforeClassAttribute/test.phpt | 4 +- .../TestCase/WithDataProvider/test.phpt | 4 +- .../Version11/TestCase/WithSetUp/test.phpt | 6 +- .../TestCase/WithSetUpBeforeClass/test.phpt | 4 +- .../Version11/TestCase/WithTearDown/test.phpt | 6 +- .../TestCase/WithTearDownAfterClass/test.phpt | 4 +- .../test.phpt | 2 +- .../WithMaximumDurationAnnotation/test.phpt | 4 +- .../WithMaximumDurationAttribute/test.phpt | 2 +- .../test.phpt | 8 +-- .../test.phpt | 2 +- .../WithSlowThresholdAnnotation/test.phpt | 4 +- test/Unit/Reporter/DefaultReporterTest.php | 61 ++++++++----------- 117 files changed, 388 insertions(+), 423 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f18d92..58b6799e 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.9.0...main`][2.9.0...main]. +### Changed + +- Stopped reporting the maximum duration ([#450]), by [@localheinz] and [@mvorisek] + ## [`2.9.0`][2.9.0] For a full diff see [`2.8.0...2.9.0`][2.8.0...2.9.0]. @@ -263,6 +267,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#396]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/396 [#447]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/447 [#448]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/448 +[#450]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/450 [@HypeMC]: https://github.com/HypeMC [@localheinz]: https://github.com/localheinz diff --git a/README.md b/README.md index d06e24e1..6504a7bc 100644 --- a/README.md +++ b/README.md @@ -352,16 +352,16 @@ Random Seed: 1676103726 Detected 11 tests that took longer than expected. - 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 + 1. 1.604 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#9 + 2. 1.505 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#8 + 3. 1.403 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#7 + 4. 1.303 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#6 + 5. 1.205 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#5 + 6. 1.103 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#4 + 7. 1.005 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3 + 8. 0.905 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2 + 9. 0.805 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1 +10. 0.705 Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#0 There is 1 additional slow test that is not listed here. diff --git a/src/Extension.php b/src/Extension.php index c04a0d8b..e67d1879 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -59,7 +59,6 @@ public function __construct(array $options = []) $this->collector = new Collector\DefaultCollector(); $this->reporter = new Reporter\DefaultReporter( new Formatter\DefaultDurationFormatter(), - $maximumDuration, $maximumCount, ); } @@ -214,7 +213,6 @@ public function bootstrap( $collector = new Collector\DefaultCollector(); $reporter = new Reporter\DefaultReporter( new Formatter\DefaultDurationFormatter(), - $maximumDuration, $maximumCount, ); diff --git a/src/Reporter/DefaultReporter.php b/src/Reporter/DefaultReporter.php index affaa7b9..a484f3f2 100644 --- a/src/Reporter/DefaultReporter.php +++ b/src/Reporter/DefaultReporter.php @@ -15,7 +15,6 @@ use Ergebnis\PHPUnit\SlowTestDetector\Comparator; use Ergebnis\PHPUnit\SlowTestDetector\Count; -use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\Formatter; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; @@ -26,16 +25,13 @@ final class DefaultReporter implements Reporter { private Comparator\DurationComparator $durationComparator; private Count $maximumCount; - private Duration $maximumDuration; private Formatter\DurationFormatter $durationFormatter; public function __construct( Formatter\DurationFormatter $durationFormatter, - Duration $maximumDuration, Count $maximumCount ) { $this->durationFormatter = $durationFormatter; - $this->maximumDuration = $maximumDuration; $this->maximumCount = $maximumCount; $this->durationComparator = new Comparator\DurationComparator(); } @@ -101,25 +97,12 @@ private function list(SlowTest ...$slowTests): string /** @var SlowTest $slowestTest */ $slowestTest = \reset($slowTestsToReport); - $longestMaximumDuration = \array_reduce( - $slowTestsToReport, - static function (Duration $maximumDuration, SlowTest $slowTest): Duration { - if ($maximumDuration->isLessThan($slowTest->maximumDuration())) { - return $slowTest->maximumDuration(); - } - - return $maximumDuration; - }, - $this->maximumDuration, - ); - $durationFormatter = $this->durationFormatter; $numberWidth = \strlen((string) \count($slowTestsToReport)); $durationWidth = \strlen($durationFormatter->format($slowestTest->duration())); - $maximumDurationWidth = \strlen($durationFormatter->format($longestMaximumDuration)); - $items = \array_map(static function (int $number, SlowTest $slowTest) use ($numberWidth, $durationFormatter, $durationWidth, $maximumDurationWidth): string { + $items = \array_map(static function (int $number, SlowTest $slowTest) use ($numberWidth, $durationFormatter, $durationWidth): string { $formattedNumber = \str_pad( (string) $number, $numberWidth, @@ -134,20 +117,10 @@ static function (Duration $maximumDuration, SlowTest $slowTest): Duration { \STR_PAD_LEFT, ); - $formattedMaximumDuration = \sprintf( - '(%s)', - \str_pad( - $durationFormatter->format($slowTest->maximumDuration()), - $maximumDurationWidth, - ' ', - \STR_PAD_LEFT, - ), - ); - $testName = $slowTest->testIdentifier()->toString(); return <<numberBetween(0)), Count::fromInt($faker->numberBetween(1)), ); @@ -52,17 +51,15 @@ public function testReportReturnsEmptyStringWhenThereAreNoSlowTests(): void } /** - * @dataProvider provideExpectedReportMaximumDurationMaximumCountAndSlowTests + * @dataProvider provideExpectedReportMaximumCountAndSlowTests */ public function testReportReturnsReportWhenThereAreFewerSlowTestsThanMaximumCount( string $expectedReport, - Duration $maximumDuration, Count $maximumCount, SlowTest ...$slowTests ): void { $reporter = new Reporter\DefaultReporter( new Formatter\DefaultDurationFormatter(), - $maximumDuration, $maximumCount, ); @@ -71,16 +68,15 @@ public function testReportReturnsReportWhenThereAreFewerSlowTestsThanMaximumCoun self::assertSame($expectedReport, $report); } - public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTests(): iterable + public static function provideExpectedReportMaximumCountAndSlowTests(): iterable { $values = [ 'header-singular' => [ <<<'TXT' Detected 1 test that took longer than expected. -1. 0.300 (0.100) FooTest::test +1. 0.300 FooTest::test TXT, - Duration::fromMilliseconds(500), Count::fromInt(1), [ SlowTest::create( @@ -94,10 +90,9 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 2 tests that took longer than expected. -1. 0.300 (0.100) FooTest::test -2. 0.275 (0.100) BarTest::test +1. 0.300 FooTest::test +2. 0.275 BarTest::test TXT, - Duration::fromMilliseconds(500), Count::fromInt(2), [ SlowTest::create( @@ -116,11 +111,10 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 3 tests that took longer than expected. -1. 0.300 (0.100) FooTest::test -2. 0.275 (0.100) BarTest::test -3. 0.250 (0.100) BazTest::test +1. 0.300 FooTest::test +2. 0.275 BarTest::test +3. 0.250 BazTest::test TXT, - Duration::fromMilliseconds(500), Count::fromInt(3), [ SlowTest::create( @@ -144,11 +138,10 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 3 tests that took longer than expected. -1. 0.300 (0.100) FooTest::test -2. 0.275 (0.100) BarTest::test -3. 0.250 (0.100) BazTest::test +1. 0.300 FooTest::test +2. 0.275 BarTest::test +3. 0.250 BazTest::test TXT, - Duration::fromMilliseconds(500), Count::fromInt(3), [ SlowTest::create( @@ -168,22 +161,21 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe ), ], ], - 'list-different-maximum-duration' => [ + 'list-long-durations' => [ <<<'TXT' Detected 10 tests that took longer than expected. - 1. 20:50.000 (16:40.000) FooTest::test - 2. 9:35.000 ( 8:20.000) BarTest::test - 3. 0.250 ( 0.100) BazTest::test - 4. 0.200 ( 0.100) QuxTest::test - 5. 0.160 ( 0.100) QuuxTest::test - 6. 0.150 ( 0.100) CorgeTest::test - 7. 0.140 ( 0.100) GraultTest::test - 8. 0.130 ( 0.100) GarplyTest::test - 9. 0.120 ( 0.100) WaldoTest::test -10. 0.110 ( 0.100) FredTest::test + 1. 20:50.000 FooTest::test + 2. 9:35.000 BarTest::test + 3. 0.250 BazTest::test + 4. 0.200 QuxTest::test + 5. 0.160 QuuxTest::test + 6. 0.150 CorgeTest::test + 7. 0.140 GraultTest::test + 8. 0.130 GarplyTest::test + 9. 0.120 WaldoTest::test +10. 0.110 FredTest::test TXT, - Duration::fromMilliseconds(500), Count::fromInt(10), [ SlowTest::create( @@ -242,11 +234,10 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 2 tests that took longer than expected. -1. 0.300 (0.100) FooTest::test +1. 0.300 FooTest::test There is 1 additional slow test that is not listed here. TXT, - Duration::fromMilliseconds(500), Count::fromInt(1), [ SlowTest::create( @@ -265,11 +256,10 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 3 tests that took longer than expected. -1. 0.300 (0.100) FooTest::test +1. 0.300 FooTest::test There are 2 additional slow tests that are not listed here. TXT, - Duration::fromMilliseconds(500), Count::fromInt(1), [ SlowTest::create( @@ -291,10 +281,9 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe ], ]; - foreach ($values as $key => [$expected, $maximumDuration, $maximumCount, $slowTests]) { + foreach ($values as $key => [$expected, $maximumCount, $slowTests]) { yield $key => [ $expected, - $maximumDuration, $maximumCount, ...$slowTests, ];