From 237402e09b78d9d7e19d3ff18b85094896c159aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Thu, 9 Feb 2023 19:50:20 +0100 Subject: [PATCH] Enhancement: Allow configuring the maximum duration via maximum-duration parameter --- CHANGELOG.md | 5 +++ src/Extension.php | 4 +++ .../MaximumDuration/Default/phpunit.xml | 26 ++++++++++++++ .../MaximumDuration/Default/test.phpt | 36 +++++++++++++++++++ .../MaximumDuration/Fifty/phpunit.xml | 26 ++++++++++++++ test/EndToEnd/MaximumDuration/Fifty/test.phpt | 36 +++++++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 test/EndToEnd/MaximumDuration/Default/phpunit.xml create mode 100644 test/EndToEnd/MaximumDuration/Default/test.phpt create mode 100644 test/EndToEnd/MaximumDuration/Fifty/phpunit.xml create mode 100644 test/EndToEnd/MaximumDuration/Fifty/test.phpt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cf0053b..a4509bcf 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 [`1.0.0...main`][1.0.0...main]. +### Changed + +- Allowed configuring the maximum duration via `maximum-parameter` ([#212]), by [@localheinz] + ### Fixed - Removed possibility to configure maximum count of reported tests using the `MAXIMUM_NUMBER` environment variable ([#211]), by [@localheinz] @@ -73,5 +77,6 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#47]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/47 [#49]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/49 [#211]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/211 +[#212]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/212 [@localheinz]: https://github.com/localheinz diff --git a/src/Extension.php b/src/Extension.php index f7f1725f..7adcef5b 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -27,6 +27,10 @@ public function bootstrap( $maximumDuration = MaximumDuration::fromMilliseconds(125); + if ($parameters->has('maximum-duration')) { + $maximumDuration = MaximumDuration::fromMilliseconds((int) $parameters->get('maximum-duration')); + } + $collector = new Collector\DefaultCollector(); $reporter = new Reporter\DefaultReporter( diff --git a/test/EndToEnd/MaximumDuration/Default/phpunit.xml b/test/EndToEnd/MaximumDuration/Default/phpunit.xml new file mode 100644 index 00000000..62806bde --- /dev/null +++ b/test/EndToEnd/MaximumDuration/Default/phpunit.xml @@ -0,0 +1,26 @@ + + + + + + + ../../../Fixture/ + + + diff --git a/test/EndToEnd/MaximumDuration/Default/test.phpt b/test/EndToEnd/MaximumDuration/Default/test.phpt new file mode 100644 index 00000000..f999f395 --- /dev/null +++ b/test/EndToEnd/MaximumDuration/Default/test.phpt @@ -0,0 +1,36 @@ +--TEST-- +With default configuration of extension +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s +Configuration: test/EndToEnd/MaximumDuration/Default/phpunit.xml +Random Seed: %s + +......... 9 / 9 (100%) + +Detected 8 tests that took longer than expected. + +1,0%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsOneSecond + 5%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithSlowThresholdAnnotation#1 + 4%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithDocBlockWithSlowThresholdAnnotationWhereValueIsNotAnInt + +There are 5 additional slow tests that are not listed here. + +Time: %s, Memory: %s + +OK (9 tests, 9 assertions) diff --git a/test/EndToEnd/MaximumDuration/Fifty/phpunit.xml b/test/EndToEnd/MaximumDuration/Fifty/phpunit.xml new file mode 100644 index 00000000..62806bde --- /dev/null +++ b/test/EndToEnd/MaximumDuration/Fifty/phpunit.xml @@ -0,0 +1,26 @@ + + + + + + + ../../../Fixture/ + + + diff --git a/test/EndToEnd/MaximumDuration/Fifty/test.phpt b/test/EndToEnd/MaximumDuration/Fifty/test.phpt new file mode 100644 index 00000000..1847a7a3 --- /dev/null +++ b/test/EndToEnd/MaximumDuration/Fifty/test.phpt @@ -0,0 +1,36 @@ +--TEST-- +Configuring "maximum-duration" parameter to 50 milliseconds +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s +Configuration: test/EndToEnd/MaximumDuration/Fifty/phpunit.xml +Random Seed: %s + +......... 9 / 9 (100%) + +Detected 8 tests that took longer than expected. + +1,0%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsOneSecond + 5%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithSlowThresholdAnnotation#1 + 4%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithDocBlockWithSlowThresholdAnnotationWhereValueIsNotAnInt + +There are 5 additional slow tests that are not listed here. + +Time: %s, Memory: %s + +OK (9 tests, 9 assertions)