From f7ca8cf15f24cbb0da5dbefd5bcdf259ba16d815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 11 Feb 2025 12:42:49 +0100 Subject: [PATCH 1/2] Improve UX, show duration in/with SI units --- README.md | 22 +++++------ src/Formatter/DefaultDurationFormatter.php | 11 +++++- .../Configuration/Defaults/test.phpt | 20 +++++----- .../Configuration/MaximumCount/test.phpt | 6 +-- .../Configuration/MaximumDuration/test.phpt | 20 +++++----- .../Version06/TestCase/Bare/test.phpt | 4 +- .../Version06/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 +- .../Version06/TestCase/WithSetUp/test.phpt | 6 +-- .../TestCase/WithSetUpBeforeClass/test.phpt | 4 +- .../Version06/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 +++++----- .../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 +- .../Configuration/Defaults/test.phpt | 20 +++++----- .../Configuration/MaximumCount/test.phpt | 6 +-- .../Configuration/MaximumDuration/test.phpt | 20 +++++----- .../Version12/TestCase/Bare/test.phpt | 4 +- .../Version12/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 +- .../Version12/TestCase/WithSetUp/test.phpt | 6 +-- .../TestCase/WithSetUpBeforeClass/test.phpt | 4 +- .../Version12/TestCase/WithTearDown/test.phpt | 6 +-- .../TestCase/WithTearDownAfterClass/test.phpt | 4 +- .../WithMaximumDurationAttribute/test.phpt | 2 +- .../test.phpt | 8 ++-- .../DefaultDurationFormatterTest.php | 8 ++-- test/Unit/Reporter/DefaultReporterTest.php | 38 +++++++++---------- 155 files changed, 516 insertions(+), 509 deletions(-) diff --git a/README.md b/README.md index bb32596d..0b9de1ef 100644 --- a/README.md +++ b/README.md @@ -339,7 +339,7 @@ You can configure the maximum duration for a single test case with - `phpunit/phpunit:^8.5.19` - `phpunit/phpunit:^9.0.0` -The following example configures the maximum durations for single test cases to 5.000 ms, 4.000 ms, and 3.000 ms: +The following example configures the maximum durations for single test cases to 5.000 s, 4.000 s, and 3.000 s: ```php [ Duration::fromSecondsAndNanoseconds( 0, 123999000 ), - '0.123', + '123 ms', ], 'seconds-digits-one' => [ Duration::fromSecondsAndNanoseconds( 1, 234456789 ), - '1.234', + '1.234 s', ], 'seconds-digits-two' => [ Duration::fromSecondsAndNanoseconds( 12, 345678912 ), - '12.345', + '12.345 s', ], 'minutes-digits-one' => [ Duration::fromSecondsAndNanoseconds( diff --git a/test/Unit/Reporter/DefaultReporterTest.php b/test/Unit/Reporter/DefaultReporterTest.php index c1a14d0b..bb7394c1 100644 --- a/test/Unit/Reporter/DefaultReporterTest.php +++ b/test/Unit/Reporter/DefaultReporterTest.php @@ -85,7 +85,7 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 1 test where the duration exceeded the maximum duration. -1. 0.300 (0.100) FooTest::test +1. 300 ms (100 ms) FooTest::test TXT , Duration::fromMilliseconds(500), @@ -103,8 +103,8 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 2 tests where the duration exceeded the maximum duration. -1. 0.300 (0.100) FooTest::test -2. 0.275 (0.100) BarTest::test +1. 300 ms (100 ms) FooTest::test +2. 275 ms (100 ms) BarTest::test TXT , Duration::fromMilliseconds(500), @@ -128,9 +128,9 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 3 tests where the duration exceeded the maximum duration. -1. 0.300 (0.100) FooTest::test -2. 0.275 (0.100) BarTest::test -3. 0.250 (0.100) BazTest::test +1. 300 ms (100 ms) FooTest::test +2. 275 ms (100 ms) BarTest::test +3. 250 ms (100 ms) BazTest::test TXT , Duration::fromMilliseconds(500), @@ -160,9 +160,9 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 3 tests where the duration exceeded the maximum duration. -1. 0.300 (0.100) FooTest::test -2. 0.275 (0.100) BarTest::test -3. 0.250 (0.100) BazTest::test +1. 300 ms (100 ms) FooTest::test +2. 275 ms (100 ms) BarTest::test +3. 250 ms (100 ms) BazTest::test TXT , Duration::fromMilliseconds(500), @@ -194,14 +194,14 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe 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 + 3. 250 ms ( 100 ms) BazTest::test + 4. 200 ms ( 100 ms) QuxTest::test + 5. 160 ms ( 100 ms) QuuxTest::test + 6. 150 ms ( 100 ms) CorgeTest::test + 7. 140 ms ( 100 ms) GraultTest::test + 8. 130 ms ( 100 ms) GarplyTest::test + 9. 120 ms ( 100 ms) WaldoTest::test +10. 110 ms ( 100 ms) FredTest::test TXT , Duration::fromMilliseconds(500), @@ -273,7 +273,7 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 2 tests where the duration exceeded the maximum duration. -1. 0.300 (0.100) FooTest::test +1. 300 ms (100 ms) FooTest::test There is 1 additional slow test that is not listed here. TXT @@ -299,7 +299,7 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe <<<'TXT' Detected 3 tests where the duration exceeded the maximum duration. -1. 0.300 (0.100) FooTest::test +1. 300 ms (100 ms) FooTest::test There are 2 additional slow tests that are not listed here. TXT From 61c70856f9c0362ac27cf2346b98d84b839d4772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 17 Feb 2025 13:05:01 +0100 Subject: [PATCH 2/2] address review --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b9de1ef..2e3c2002 100644 --- a/README.md +++ b/README.md @@ -339,7 +339,7 @@ You can configure the maximum duration for a single test case with - `phpunit/phpunit:^8.5.19` - `phpunit/phpunit:^9.0.0` -The following example configures the maximum durations for single test cases to 5.000 s, 4.000 s, and 3.000 s: +The following example configures the maximum durations for single test cases to 5, 4, and 3 seconds: ```php