Skip to content

Commit 4497191

Browse files
committed
Enhancement: Allow configuring the maximum duration via maximum-duration parameter
1 parent 07ea6a4 commit 4497191

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
For a full diff see [`1.0.0...main`][1.0.0...main].
1010

11+
### Changed
12+
13+
- Allowed configuring the maximum duration via `maximum-parameter` ([#212]), by [@localheinz]
1114
### Fixed
1215

1316
- Removed possibility to configure maximum count of reported tests using the `MAXIMUM_NUMBER` environment variable ([#211]), by [@localheinz]
@@ -73,5 +76,6 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
7376
[#47]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/47
7477
[#49]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/49
7578
[#211]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/211
79+
[#212]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/212
7680

7781
[@localheinz]: https://github.com/localheinz

src/Extension.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function bootstrap(
2727

2828
$maximumDuration = MaximumDuration::fromMilliseconds(125);
2929

30+
if ($parameters->has('maximum-duration')) {
31+
$maximumDuration = MaximumDuration::fromMilliseconds((int) $parameters->get('maximum-duration'));
32+
}
33+
3034
$collector = new Collector\DefaultCollector();
3135

3236
$reporter = new Reporter\DefaultReporter(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../vendor/phpunit/phpunit/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
beStrictAboutTodoAnnotatedTests="true"
8+
bootstrap="../../../../vendor/autoload.php"
9+
cacheResult="false"
10+
colors="true"
11+
columns="max"
12+
executionOrder="random"
13+
stopOnError="false"
14+
stopOnFailure="false"
15+
stopOnIncomplete="false"
16+
stopOnSkipped="false"
17+
>
18+
<extensions>
19+
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
20+
</extensions>
21+
<testsuites>
22+
<testsuite name="unit">
23+
<directory>../../../Fixture/</directory>
24+
</testsuite>
25+
</testsuites>
26+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
With default configuration of extension
3+
--FILE--
4+
<?php
5+
6+
declare(strict_types=1);
7+
8+
use PHPUnit\TextUI;
9+
10+
$_SERVER['argv'][] = '--configuration=test/EndToEnd/MaximumDuration/Default/phpunit.xml';
11+
12+
require_once __DIR__ . '/../../../../vendor/autoload.php';
13+
14+
$application = new TextUI\Application();
15+
16+
$application->run($_SERVER['argv']);
17+
--EXPECTF--
18+
PHPUnit %s by Sebastian Bergmann and contributors.
19+
20+
Runtime: %s
21+
Configuration: test/EndToEnd/MaximumDuration/Default/phpunit.xml
22+
Random Seed: %s
23+
24+
......... 9 / 9 (100%)
25+
26+
Detected 8 tests that took longer than expected.
27+
28+
1,0%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsOneSecond
29+
5%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithSlowThresholdAnnotation#1
30+
4%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithDocBlockWithSlowThresholdAnnotationWhereValueIsNotAnInt
31+
32+
There are 5 additional slow tests that are not listed here.
33+
34+
Time: %s, Memory: %s
35+
36+
OK (9 tests, 9 assertions)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../vendor/phpunit/phpunit/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
beStrictAboutTodoAnnotatedTests="true"
8+
bootstrap="../../../../vendor/autoload.php"
9+
cacheResult="false"
10+
colors="true"
11+
columns="max"
12+
executionOrder="random"
13+
stopOnError="false"
14+
stopOnFailure="false"
15+
stopOnIncomplete="false"
16+
stopOnSkipped="false"
17+
>
18+
<extensions>
19+
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
20+
</extensions>
21+
<testsuites>
22+
<testsuite name="unit">
23+
<directory>../../../Fixture/</directory>
24+
</testsuite>
25+
</testsuites>
26+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Configuring "maximum-duration" parameter to 50 milliseconds
3+
--FILE--
4+
<?php
5+
6+
declare(strict_types=1);
7+
8+
use PHPUnit\TextUI;
9+
10+
$_SERVER['argv'][] = '--configuration=test/EndToEnd/MaximumDuration/Fifty/phpunit.xml';
11+
12+
require_once __DIR__ . '/../../../../vendor/autoload.php';
13+
14+
$application = new TextUI\Application();
15+
16+
$application->run($_SERVER['argv']);
17+
--EXPECTF--
18+
PHPUnit %s by Sebastian Bergmann and contributors.
19+
20+
Runtime: %s
21+
Configuration: test/EndToEnd/MaximumDuration/Fifty/phpunit.xml
22+
Random Seed: %s
23+
24+
......... 9 / 9 (100%)
25+
26+
Detected 8 tests that took longer than expected.
27+
28+
1,0%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsOneSecond
29+
5%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithSlowThresholdAnnotation#1
30+
4%s ms (125 ms) Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\SleeperTest::testSleeperSleepsWithDocBlockWithSlowThresholdAnnotationWhereValueIsNotAnInt
31+
32+
There are 5 additional slow tests that are not listed here.
33+
34+
Time: %s, Memory: %s
35+
36+
OK (9 tests, 9 assertions)

0 commit comments

Comments
 (0)