Skip to content

Commit

Permalink
Merge pull request #212 from ergebnis/feature/maximum-duration
Browse files Browse the repository at this point in the history
Enhancement: Allow configuring the maximum duration via `maximum-duration` parameter
  • Loading branch information
localheinz committed Feb 9, 2023
2 parents 7b0691c + 237402e commit 779126d
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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]
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/Extension.php
Expand Up @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions test/EndToEnd/MaximumDuration/Default/phpunit.xml
@@ -0,0 +1,26 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../../../../vendor/autoload.php"
cacheResult="false"
colors="true"
columns="max"
executionOrder="random"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="unit">
<directory>../../../Fixture/</directory>
</testsuite>
</testsuites>
</phpunit>
36 changes: 36 additions & 0 deletions test/EndToEnd/MaximumDuration/Default/test.phpt
@@ -0,0 +1,36 @@
--TEST--
With default configuration of extension
--FILE--
<?php

declare(strict_types=1);

use PHPUnit\TextUI;

$_SERVER['argv'][] = '--configuration=test/EndToEnd/MaximumDuration/Default/phpunit.xml';

require_once __DIR__ . '/../../../../vendor/autoload.php';

$application = new TextUI\Application();

$application->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)
26 changes: 26 additions & 0 deletions test/EndToEnd/MaximumDuration/Fifty/phpunit.xml
@@ -0,0 +1,26 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../../../../vendor/autoload.php"
cacheResult="false"
colors="true"
columns="max"
executionOrder="random"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="unit">
<directory>../../../Fixture/</directory>
</testsuite>
</testsuites>
</phpunit>
36 changes: 36 additions & 0 deletions test/EndToEnd/MaximumDuration/Fifty/test.phpt
@@ -0,0 +1,36 @@
--TEST--
Configuring "maximum-duration" parameter to 50 milliseconds
--FILE--
<?php

declare(strict_types=1);

use PHPUnit\TextUI;

$_SERVER['argv'][] = '--configuration=test/EndToEnd/MaximumDuration/Fifty/phpunit.xml';

require_once __DIR__ . '/../../../../vendor/autoload.php';

$application = new TextUI\Application();

$application->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)

0 comments on commit 779126d

Please sign in to comment.