From 3b8e095dbbbbd29f3f73ccb488125f22afa93952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 5 Nov 2023 18:16:38 +0100 Subject: [PATCH] Enhancement: Add support for phpunit/phpunit:^9.6.0 --- .github/settings.yml | 27 +- .github/workflows/integrate.yaml | 23 +- CHANGELOG.md | 5 + Makefile | 5 +- README.md | 56 ++++- composer-require-checker.json | 6 +- composer.json | 2 +- composer.lock | 2 +- psalm-baseline.xml | 20 +- rector.php | 4 - src/Extension.php | 232 +++++++++++++++--- test/EndToEnd/Default/test.phpt | 43 ---- test/EndToEnd/MaximumDuration/Fifty/test.phpt | 37 --- .../{ => Version10}/Default/SleeperTest.php | 2 +- .../{ => Version10}/Default/phpunit.xml | 4 +- test/EndToEnd/Version10/Default/test.phpt | 43 ++++ .../MaximumCount/Three/SleeperTest.php | 2 +- .../MaximumCount/Three/phpunit.xml | 4 +- .../MaximumCount/Three/test.phpt | 12 +- .../MaximumDuration/Fifty/SleeperTest.php | 2 +- .../MaximumDuration/Fifty/phpunit.xml | 4 +- .../Version10/MaximumDuration/Fifty/test.phpt | 37 +++ .../{ => Version10}/NoOutput/SleeperTest.php | 2 +- .../{ => Version10}/NoOutput/phpunit.xml | 4 +- .../{ => Version10}/NoOutput/test.phpt | 4 +- test/EndToEnd/{ => Version10}/phpunit.xml | 10 +- .../EndToEnd/Version9/Default/SleeperTest.php | 66 +++++ test/EndToEnd/Version9/Default/phpunit.xml | 28 +++ test/EndToEnd/Version9/Default/test.phpt | 41 ++++ .../MaximumCount/Three/SleeperTest.php | 66 +++++ .../Version9/MaximumCount/Three/phpunit.xml | 36 +++ .../Version9/MaximumCount/Three/test.phpt | 34 +++ .../MaximumDuration/Fifty/SleeperTest.php | 172 +++++++++++++ .../MaximumDuration/Fifty/phpunit.xml | 36 +++ .../Version9/MaximumDuration/Fifty/test.phpt | 35 +++ test/EndToEnd/Version9/phpunit.xml | 27 ++ 36 files changed, 964 insertions(+), 169 deletions(-) delete mode 100644 test/EndToEnd/Default/test.phpt delete mode 100644 test/EndToEnd/MaximumDuration/Fifty/test.phpt rename test/EndToEnd/{ => Version10}/Default/SleeperTest.php (95%) rename test/EndToEnd/{ => Version10}/Default/phpunit.xml (88%) create mode 100644 test/EndToEnd/Version10/Default/test.phpt rename test/EndToEnd/{ => Version10}/MaximumCount/Three/SleeperTest.php (94%) rename test/EndToEnd/{ => Version10}/MaximumCount/Three/phpunit.xml (85%) rename test/EndToEnd/{ => Version10}/MaximumCount/Three/test.phpt (56%) rename test/EndToEnd/{ => Version10}/MaximumDuration/Fifty/SleeperTest.php (98%) rename test/EndToEnd/{ => Version10}/MaximumDuration/Fifty/phpunit.xml (85%) create mode 100644 test/EndToEnd/Version10/MaximumDuration/Fifty/test.phpt rename test/EndToEnd/{ => Version10}/NoOutput/SleeperTest.php (91%) rename test/EndToEnd/{ => Version10}/NoOutput/phpunit.xml (88%) rename test/EndToEnd/{ => Version10}/NoOutput/test.phpt (62%) rename test/EndToEnd/{ => Version10}/phpunit.xml (79%) create mode 100644 test/EndToEnd/Version9/Default/SleeperTest.php create mode 100644 test/EndToEnd/Version9/Default/phpunit.xml create mode 100644 test/EndToEnd/Version9/Default/test.phpt create mode 100644 test/EndToEnd/Version9/MaximumCount/Three/SleeperTest.php create mode 100644 test/EndToEnd/Version9/MaximumCount/Three/phpunit.xml create mode 100644 test/EndToEnd/Version9/MaximumCount/Three/test.phpt create mode 100644 test/EndToEnd/Version9/MaximumDuration/Fifty/SleeperTest.php create mode 100644 test/EndToEnd/Version9/MaximumDuration/Fifty/phpunit.xml create mode 100644 test/EndToEnd/Version9/MaximumDuration/Fifty/test.phpt create mode 100644 test/EndToEnd/Version9/phpunit.xml diff --git a/.github/settings.yml b/.github/settings.yml index f817a8cc..3b540e9e 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -21,15 +21,24 @@ branches: - context: "Refactoring (8.1, locked)" - context: "Security Analysis (8.1, locked)" - context: "Static Code Analysis (8.1, locked)" - - context: "Tests (8.1, highest)" - - context: "Tests (8.1, locked)" - - context: "Tests (8.1, lowest)" - - context: "Tests (8.2, highest)" - - context: "Tests (8.2, locked)" - - context: "Tests (8.2, lowest)" - - context: "Tests (8.3, highest)" - - context: "Tests (8.3, locked)" - - context: "Tests (8.3, lowest)" + - context: "Tests (8.1, 10.4.0, highest)" + - context: "Tests (8.1, 10.4.0, locked)" + - context: "Tests (8.1, 10.4.0, lowest)" + - context: "Tests (8.1, 9.6.0, highest)" + - context: "Tests (8.1, 9.6.0, locked)" + - context: "Tests (8.1, 9.6.0, lowest)" + - context: "Tests (8.2, 10.4.0, highest)" + - context: "Tests (8.2, 10.4.0, locked)" + - context: "Tests (8.2, 10.4.0, lowest)" + - context: "Tests (8.2, 9.6.0, highest)" + - context: "Tests (8.2, 9.6.0, locked)" + - context: "Tests (8.2, 9.6.0, lowest)" + - context: "Tests (8.3, 10.4.0, highest)" + - context: "Tests (8.3, 10.4.0, locked)" + - context: "Tests (8.3, 10.4.0, lowest)" + - context: "Tests (8.3, 9.6.0, highest)" + - context: "Tests (8.3, 9.6.0, locked)" + - context: "Tests (8.3, 9.6.0, lowest)" strict: false restrictions: diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 58664fdb..d00702a3 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -449,6 +449,10 @@ jobs: - "8.2" - "8.3" + phpunit-version: + - "9.6.0" + - "10.4.0" + dependencies: - "lowest" - "locked" @@ -481,16 +485,25 @@ jobs: uses: "actions/cache@v3.3.2" with: path: "${{ env.COMPOSER_CACHE_DIR }}" - key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}" - restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" + key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-phpunit-${{ matrix.phpunit-version }}-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-phpunit-${{ matrix.phpunit-version }}-" + + - name: "Require phpunit/phpunit:^${{ matrix.phpunit-version }}" + run: "composer require phpunit/phpunit:^${{ matrix.phpunit-version }} --ansi --no-interaction --no-progress --update-with-all-dependencies" - name: "Install ${{ matrix.dependencies }} dependencies with composer" uses: "ergebnis/.github/actions/composer/install@1.8.0" with: dependencies: "${{ matrix.dependencies }}" - - name: "Run unit tests with phpunit/phpunit" + - name: "Run unit tests with phpunit/phpunit:10.4.0" + if: "matrix.phpunit-version == '10.4.0'" run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml" - - name: "Run end-to-end tests with phpunit/phpunit" - run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/phpunit.xml" + - name: "Run end-to-end tests with phpunit/phpunit:10.4.0" + if: "matrix.phpunit-version == '10.4.0'" + run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version10/phpunit.xml" + + - name: "Run end-to-end tests with phpunit/phpunit:9.6.0" + if: "matrix.phpunit-version == '9.6.0'" + run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version9/phpunit.xml" diff --git a/CHANGELOG.md b/CHANGELOG.md index e41135a6..cdcbe333 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.3.2...main`][2.3.2...main]. +### Added + +- Added support for `phpunit/phpunit:^9.6.0` ([#341]), by [@localheinz] + ### Changed - Extracted `Duration` ([#351]), by [@localheinz] @@ -175,6 +179,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0]. [#272]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/272 [#273]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/273 [#340]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/340 +[#341]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/341 [#342]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/342 [#343]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/343 [#350]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/350 diff --git a/Makefile b/Makefile index de28c7b5..085a510b 100644 --- a/Makefile +++ b/Makefile @@ -59,8 +59,9 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an .PHONY: tests tests: vendor ## Runs unit and end-to-end tests with phpunit/phpunit mkdir -p .build/phpunit - vendor/bin/phpunit --configuration=test/Unit/phpunit.xml - vendor/bin/phpunit --configuration=test/EndToEnd/phpunit.xml + composer require phpunit/phpunit:10.4.0 --no-interaction --no-progress --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/Unit/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --no-progress + composer require phpunit/phpunit:10.4.0 --no-interaction --no-progress --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version10/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --no-progress + composer require phpunit/phpunit:9.6.0 --no-interaction --no-progress --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version9/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --no-progress vendor: composer.json composer.lock composer validate --strict diff --git a/README.md b/README.md index 2b950f7e..2e960725 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Download `phpunit-slow-test-detector.phar` from the [latest release](https://git ### Bootstrapping the extension as a `composer` package -To bootstrap the extension as a `composer` package, adjust your `phpunit.xml` configuration file and configure the [`` element](https://docs.phpunit.de/en/10.4/configuration.html#the-extensions-element): +To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^10.4.0`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/10.4/configuration.html#the-extensions-element): ```diff ``` +To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^9.6.0`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/9.6/configuration.html#the-extensions-element): + +```diff + ++ ++ ++ + + + test/Unit/ + + + +``` + ### Bootstrapping the extension as a PHAR -To bootstrap the extension as a PHAR, adjust your `phpunit.xml` configuration file and configure the [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.4/configuration.html#the-extensionsdirectory-attribute) of the [`` element](https://docs.phpunit.de/en/10.4/configuration.html#the-phpunit-element): +To bootstrap the extension as a PHAR when using `phpunit/phpunit:^10.4.0`, adjust your `phpunit.xml` configuration file and configure the [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.4/configuration.html#the-extensionsdirectory-attribute) of the [`` element](https://docs.phpunit.de/en/10.4/configuration.html#the-phpunit-element): ```diff ``` +The following example configures the maximum count of slow tests to three, and the maximum duration for all tests to 250 milliseconds when using `phpunit/phpunit:^9.6.0`: + +```diff + + +- ++ ++ ++ ++ ++ 3 ++ ++ ++ 250 ++ ++ ++ ++ + + + + test/Unit/ + + + +``` + #### Configuring the maximum duration per test case You can configure the maximum duration for a single test with a `@maximumDuration` (or `@slowThreshold`) annotation in the DocBlock. diff --git a/composer-require-checker.json b/composer-require-checker.json index b8b091ad..52337aef 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -1,3 +1,7 @@ { - "symbol-whitelist": [] + "symbol-whitelist": [ + "PHPUnit\\Runner\\AfterLastTestHook", + "PHPUnit\\Runner\\AfterSuccessfulTestHook", + "PHPUnit\\Runner\\BeforeFirstTestHook" + ] } diff --git a/composer.json b/composer.json index 900cb85b..e33abf2e 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "phpunit/phpunit": "^10.4.0" + "phpunit/phpunit": "^9.6.0 || ^10.4.0" }, "require-dev": { "ergebnis/composer-normalize": "^2.39.0", diff --git a/composer.lock b/composer.lock index 23c93891..c28df8a7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e8f51f8982d4e7958624c2f1ba1d83c9", + "content-hash": "765c3e09035ad6746dab791b29ccbab1", "packages": [ { "name": "myclabs/deep-copy", diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 5d32a646..a3db4ca5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,6 +1,9 @@ + + Extension + Extension @@ -30,6 +33,19 @@ $maximumDuration + + TestPassedSubscriber + + + + + TestPreparedSubscriber + + + + + TestRunnerExecutionFinishedSubscriber + @@ -46,12 +62,12 @@ NullReporter - + provideMillisecondsGreaterThanDefaultMaximumDuration - + provideMillisecondsGreaterThanDefaultMaximumDuration diff --git a/rector.php b/rector.php index 90708320..e3c4911e 100644 --- a/rector.php +++ b/rector.php @@ -31,8 +31,4 @@ $rectorConfig->rules([ Php81\Rector\Property\ReadOnlyPropertyRector::class, ]); - - $rectorConfig->sets([ - PHPUnit\Set\PHPUnitSetList::PHPUNIT_100, - ]); }; diff --git a/src/Extension.php b/src/Extension.php index 61b3ec88..ab233260 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -15,49 +15,211 @@ use PHPUnit\Runner; use PHPUnit\TextUI; +use PHPUnit\Util; -final class Extension implements Runner\Extension\Extension -{ - public function bootstrap( - TextUI\Configuration\Configuration $configuration, - Runner\Extension\Facade $facade, - Runner\Extension\ParameterCollection $parameters, - ): void { - if ($configuration->noOutput()) { - return; - } +if (1 !== \preg_match('/(?P\d+)\.(?P\d+)\.(?P\d+)/', Runner\Version::id(), $matches)) { + throw new \RuntimeException(\sprintf( + 'Unable to determine PHPUnit version from version identifier "%s".', + Runner\Version::id(), + )); +} + +$major = (int) $matches['major']; + +if (10 <= $major) { + /** + * @internal + */ + final class Extension implements Runner\Extension\Extension + { + public function bootstrap( + TextUI\Configuration\Configuration $configuration, + Runner\Extension\Facade $facade, + Runner\Extension\ParameterCollection $parameters, + ): void { + if ($configuration->noOutput()) { + return; + } + + $maximumCount = Count::fromInt(10); + + if ($parameters->has('maximum-count')) { + $maximumCount = Count::fromInt((int) $parameters->get('maximum-count')); + } - $maximumCount = Count::fromInt(10); + $maximumDuration = Duration::fromMilliseconds(500); - if ($parameters->has('maximum-count')) { - $maximumCount = Count::fromInt((int) $parameters->get('maximum-count')); + if ($parameters->has('maximum-duration')) { + $maximumDuration = Duration::fromMilliseconds((int) $parameters->get('maximum-duration')); + } + + $timeKeeper = new TimeKeeper(); + $collector = new Collector\DefaultCollector(); + $reporter = new Reporter\DefaultReporter( + new Formatter\DefaultDurationFormatter(), + $maximumDuration, + $maximumCount, + ); + + $facade->registerSubscribers( + new Subscriber\TestPreparedSubscriber($timeKeeper), + new Subscriber\TestPassedSubscriber( + $maximumDuration, + $timeKeeper, + $collector, + ), + new Subscriber\TestRunnerExecutionFinishedSubscriber( + $collector, + $reporter, + ), + ); } + } +} elseif (9 === $major) { + /** + * @internal + */ + final class Extension implements + Runner\AfterLastTestHook, + Runner\AfterSuccessfulTestHook, + Runner\BeforeFirstTestHook + { + private int $suites = 0; + private readonly Duration $maximumDuration; + private readonly TimeKeeper $timeKeeper; + private readonly Collector\Collector $collector; + private readonly Reporter\Reporter $reporter; + + public function __construct(array $options = []) + { + $maximumCount = Count::fromInt(10); - $maximumDuration = Duration::fromMilliseconds(500); + if (\array_key_exists('maximum-count', $options)) { + $maximumCount = Count::fromInt((int) $options['maximum-count']); + } - if ($parameters->has('maximum-duration')) { - $maximumDuration = Duration::fromMilliseconds((int) $parameters->get('maximum-duration')); + $maximumDuration = Duration::fromMilliseconds(500); + + if (\array_key_exists('maximum-duration', $options)) { + $maximumDuration = Duration::fromMilliseconds((int) $options['maximum-duration']); + } + + $this->maximumDuration = $maximumDuration; + $this->timeKeeper = new TimeKeeper(); + $this->collector = new Collector\DefaultCollector(); + $this->reporter = new Reporter\DefaultReporter( + new Formatter\DefaultDurationFormatter(), + $maximumDuration, + $maximumCount, + ); } - $timeKeeper = new TimeKeeper(); - $collector = new Collector\DefaultCollector(); - $reporter = new Reporter\DefaultReporter( - new Formatter\DefaultDurationFormatter(), - $maximumDuration, - $maximumCount, - ); - - $facade->registerSubscribers( - new Subscriber\TestPreparedSubscriber($timeKeeper), - new Subscriber\TestPassedSubscriber( + public function executeBeforeFirstTest(): void + { + ++$this->suites; + } + + public function executeAfterSuccessfulTest( + string $test, + float $time, + ): void { + $seconds = (int) \floor($time); + $nanoseconds = (int) (($time - $seconds) * 1_000_000_000); + + $duration = Duration::fromSecondsAndNanoseconds( + $seconds, + $nanoseconds, + ); + + $maximumDuration = $this->resolveMaximumDuration($test); + + if (!$duration->isGreaterThan($maximumDuration)) { + return; + } + + $testIdentifier = TestIdentifier::fromString($test); + + $slowTest = SlowTest::create( + $testIdentifier, + $duration, $maximumDuration, - $timeKeeper, - $collector, - ), - new Subscriber\TestRunnerExecutionFinishedSubscriber( - $collector, - $reporter, - ), - ); + ); + + $this->collector->collect($slowTest); + } + + public function executeAfterLastTest(): void + { + --$this->suites; + + if (0 < $this->suites) { + return; + } + + $slowTests = $this->collector->collected(); + + if ([] === $slowTests) { + return; + } + + $report = $this->reporter->report(...$slowTests); + + if ('' === $report) { + return; + } + + echo <<maximumDuration; + } } +} else { + throw new \RuntimeException(\sprintf( + 'Unable to select extension for PHPUnit version with version identifier "%s".', + Runner\Version::id(), + )); } diff --git a/test/EndToEnd/Default/test.phpt b/test/EndToEnd/Default/test.phpt deleted file mode 100644 index 7bce1932..00000000 --- a/test/EndToEnd/Default/test.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -With default configuration of extension ---FILE-- -run($_SERVER['argv']); ---EXPECTF-- -PHPUnit %s by Sebastian Bergmann and contributors. - -Runtime: %s -Configuration: %Stest/EndToEnd/Default/phpunit.xml -Random Seed: %s - -............ 12 / 12 (100%) - -Detected 11 tests that took longer than expected. - - 1. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#10 - 2. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#9 - 3. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#8 - 4. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#7 - 5. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#6 - 6. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#5 - 7. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#4 - 8. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3 - 9. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2 -10. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1 - -There is 1 additional slow test that is not listed here. - -Time: %s, Memory: %s - -OK (12 tests, 12 assertions) diff --git a/test/EndToEnd/MaximumDuration/Fifty/test.phpt b/test/EndToEnd/MaximumDuration/Fifty/test.phpt deleted file mode 100644 index db8f5c8d..00000000 --- a/test/EndToEnd/MaximumDuration/Fifty/test.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -Configuring "maximum-duration" parameter to 50 milliseconds ---FILE-- -run($_SERVER['argv']); ---EXPECTF-- -PHPUnit %s by Sebastian Bergmann and contributors. - -Runtime: %s -Configuration: %Stest/EndToEnd/MaximumDuration/Fifty/phpunit.xml -Random Seed: %s - -.......... 10 / 10 (100%) - -Detected 6 tests that took longer than expected. - -1. 0.2%s (0.200) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromSlowThresholdAnnotation -2. 0.2%s (0.180) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentBeforeMaximumDuration -3. 0.1%s (0.160) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentAfterMaximumDuration -4. 0.1%s (0.150) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotation -5. 0.1%s (0.050) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsWithDocBlockWithMaximumDurationAnnotationWhereValueIsNotAnInt -6. 0.0%s (0.050) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsWithDocBlockWithoutSlowThresholdAnnotation - -Time: %s, Memory: %s - -OK (10 tests, 10 assertions) diff --git a/test/EndToEnd/Default/SleeperTest.php b/test/EndToEnd/Version10/Default/SleeperTest.php similarity index 95% rename from test/EndToEnd/Default/SleeperTest.php rename to test/EndToEnd/Version10/Default/SleeperTest.php index ef69c548..08d12c79 100644 --- a/test/EndToEnd/Default/SleeperTest.php +++ b/test/EndToEnd/Version10/Default/SleeperTest.php @@ -11,7 +11,7 @@ * @see https://github.com/ergebnis/phpunit-slow-test-detector */ -namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Default; +namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; diff --git a/test/EndToEnd/Default/phpunit.xml b/test/EndToEnd/Version10/Default/phpunit.xml similarity index 88% rename from test/EndToEnd/Default/phpunit.xml rename to test/EndToEnd/Version10/Default/phpunit.xml index 54e2050f..3da566c5 100644 --- a/test/EndToEnd/Default/phpunit.xml +++ b/test/EndToEnd/Version10/Default/phpunit.xml @@ -1,11 +1,11 @@ run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s +Configuration: %Stest/EndToEnd/Version10/Default/phpunit.xml +Random Seed: %s + +............ 12 / 12 (100%) + +Detected 11 tests that took longer than expected. + + 1. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#10 + 2. 1.0%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#9 + 3. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#8 + 4. 0.9%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#7 + 5. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#6 + 6. 0.8%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#5 + 7. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#4 + 8. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3 + 9. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2 +10. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\Default\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1 + +There is 1 additional slow test that is not listed here. + +Time: %s, Memory: %s + +OK (12 tests, 12 assertions) diff --git a/test/EndToEnd/MaximumCount/Three/SleeperTest.php b/test/EndToEnd/Version10/MaximumCount/Three/SleeperTest.php similarity index 94% rename from test/EndToEnd/MaximumCount/Three/SleeperTest.php rename to test/EndToEnd/Version10/MaximumCount/Three/SleeperTest.php index 3833728c..d2323fdf 100644 --- a/test/EndToEnd/MaximumCount/Three/SleeperTest.php +++ b/test/EndToEnd/Version10/MaximumCount/Three/SleeperTest.php @@ -11,7 +11,7 @@ * @see https://github.com/ergebnis/phpunit-slow-test-detector */ -namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumCount\Three; +namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumCount\Three; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; diff --git a/test/EndToEnd/MaximumCount/Three/phpunit.xml b/test/EndToEnd/Version10/MaximumCount/Three/phpunit.xml similarity index 85% rename from test/EndToEnd/MaximumCount/Three/phpunit.xml rename to test/EndToEnd/Version10/MaximumCount/Three/phpunit.xml index 63f2f4f1..f860d73d 100644 --- a/test/EndToEnd/MaximumCount/Three/phpunit.xml +++ b/test/EndToEnd/Version10/MaximumCount/Three/phpunit.xml @@ -1,11 +1,11 @@ run($_SERVER['argv']); PHPUnit %s by Sebastian Bergmann and contributors. Runtime: %s -Configuration: %Stest/EndToEnd/MaximumCount/Three/phpunit.xml +Configuration: %Stest/EndToEnd/Version10/MaximumCount/Three/phpunit.xml Random Seed: %s ..... 5 / 5 (100%) Detected 4 tests that took longer than expected. -1. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumCount\Three\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3 -2. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumCount\Three\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2 -3. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumCount\Three\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1 +1. 0.7%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumCount\Three\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#3 +2. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumCount\Three\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#2 +3. 0.6%s (0.500) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumCount\Three\SleeperTest::testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider#1 There is 1 additional slow test that is not listed here. diff --git a/test/EndToEnd/MaximumDuration/Fifty/SleeperTest.php b/test/EndToEnd/Version10/MaximumDuration/Fifty/SleeperTest.php similarity index 98% rename from test/EndToEnd/MaximumDuration/Fifty/SleeperTest.php rename to test/EndToEnd/Version10/MaximumDuration/Fifty/SleeperTest.php index f7a868c8..94f9fafb 100644 --- a/test/EndToEnd/MaximumDuration/Fifty/SleeperTest.php +++ b/test/EndToEnd/Version10/MaximumDuration/Fifty/SleeperTest.php @@ -11,7 +11,7 @@ * @see https://github.com/ergebnis/phpunit-slow-test-detector */ -namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\MaximumDuration\Fifty; +namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumDuration\Fifty; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; diff --git a/test/EndToEnd/MaximumDuration/Fifty/phpunit.xml b/test/EndToEnd/Version10/MaximumDuration/Fifty/phpunit.xml similarity index 85% rename from test/EndToEnd/MaximumDuration/Fifty/phpunit.xml rename to test/EndToEnd/Version10/MaximumDuration/Fifty/phpunit.xml index 0834e1fe..74815eaa 100644 --- a/test/EndToEnd/MaximumDuration/Fifty/phpunit.xml +++ b/test/EndToEnd/Version10/MaximumDuration/Fifty/phpunit.xml @@ -1,11 +1,11 @@ run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s +Configuration: %Stest/EndToEnd/Version10/MaximumDuration/Fifty/phpunit.xml +Random Seed: %s + +.......... 10 / 10 (100%) + +Detected 6 tests that took longer than expected. + +1. 0.2%s (0.200) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromSlowThresholdAnnotation +2. 0.2%s (0.180) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentBeforeMaximumDuration +3. 0.1%s (0.160) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentAfterMaximumDuration +4. 0.1%s (0.150) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotation +5. 0.1%s (0.050) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsWithDocBlockWithMaximumDurationAnnotationWhereValueIsNotAnInt +6. 0.0%s (0.050) Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\MaximumDuration\Fifty\SleeperTest::testSleeperSleepsWithDocBlockWithoutSlowThresholdAnnotation + +Time: %s, Memory: %s + +OK (10 tests, 10 assertions) diff --git a/test/EndToEnd/NoOutput/SleeperTest.php b/test/EndToEnd/Version10/NoOutput/SleeperTest.php similarity index 91% rename from test/EndToEnd/NoOutput/SleeperTest.php rename to test/EndToEnd/Version10/NoOutput/SleeperTest.php index ee5e2310..25749d39 100644 --- a/test/EndToEnd/NoOutput/SleeperTest.php +++ b/test/EndToEnd/Version10/NoOutput/SleeperTest.php @@ -11,7 +11,7 @@ * @see https://github.com/ergebnis/phpunit-slow-test-detector */ -namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\NoOutput; +namespace Ergebnis\PHPUnit\SlowTestDetector\Test\EndToEnd\Version10\NoOutput; use Ergebnis\PHPUnit\SlowTestDetector\Test; use PHPUnit\Framework; diff --git a/test/EndToEnd/NoOutput/phpunit.xml b/test/EndToEnd/Version10/NoOutput/phpunit.xml similarity index 88% rename from test/EndToEnd/NoOutput/phpunit.xml rename to test/EndToEnd/Version10/NoOutput/phpunit.xml index 54e2050f..3da566c5 100644 --- a/test/EndToEnd/NoOutput/phpunit.xml +++ b/test/EndToEnd/Version10/NoOutput/phpunit.xml @@ -1,11 +1,11 @@ - ../../src/ + ../../../src/ diff --git a/test/EndToEnd/Version9/Default/SleeperTest.php b/test/EndToEnd/Version9/Default/SleeperTest.php new file mode 100644 index 00000000..96a65098 --- /dev/null +++ b/test/EndToEnd/Version9/Default/SleeperTest.php @@ -0,0 +1,66 @@ +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanDefaultMaximumDuration + */ + public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable + { + $values = \range( + 550, + 1050, + 50, + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version9/Default/phpunit.xml b/test/EndToEnd/Version9/Default/phpunit.xml new file mode 100644 index 00000000..5b14ab2c --- /dev/null +++ b/test/EndToEnd/Version9/Default/phpunit.xml @@ -0,0 +1,28 @@ + + + + + + + . + + + diff --git a/test/EndToEnd/Version9/Default/test.phpt b/test/EndToEnd/Version9/Default/test.phpt new file mode 100644 index 00000000..56e9a987 --- /dev/null +++ b/test/EndToEnd/Version9/Default/test.phpt @@ -0,0 +1,41 @@ +--TEST-- +With default configuration of extension +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @dataProvider provideMillisecondsGreaterThanDefaultMaximumDuration + */ + public function testSleeperSleepsLongerThanDefaultMaximumDurationWithDataProvider(int $milliseconds): void + { + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @return \Generator + */ + public static function provideMillisecondsGreaterThanDefaultMaximumDuration(): iterable + { + $values = \range( + 550, + 700, + 50, + ); + + foreach ($values as $value) { + yield $value => [ + $value, + ]; + } + } +} diff --git a/test/EndToEnd/Version9/MaximumCount/Three/phpunit.xml b/test/EndToEnd/Version9/MaximumCount/Three/phpunit.xml new file mode 100644 index 00000000..e1c0feb4 --- /dev/null +++ b/test/EndToEnd/Version9/MaximumCount/Three/phpunit.xml @@ -0,0 +1,36 @@ + + + + + + + 3 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version9/MaximumCount/Three/test.phpt b/test/EndToEnd/Version9/MaximumCount/Three/test.phpt new file mode 100644 index 00000000..4c434741 --- /dev/null +++ b/test/EndToEnd/Version9/MaximumCount/Three/test.phpt @@ -0,0 +1,34 @@ +--TEST-- +Configuring "maximum-duration" parameter to 50 milliseconds +--FILE-- +sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * This DocBlock is intentionally left without a useful comment or annotation. + */ + public function testSleeperSleepsWithDocBlockWithoutSlowThresholdAnnotation(): void + { + $milliseconds = 90; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 3.14 + */ + public function testSleeperSleepsWithDocBlockWithMaximumDurationAnnotationWhereValueIsNotAnInt(): void + { + $milliseconds = 110; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 140 + */ + public function testSleeperSleepsShorterThanMaximumDurationFromMaximumDurationAnnotation(): void + { + $milliseconds = 130; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 150 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotation(): void + { + $milliseconds = 150; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @maximumDuration 160 + * + * @slowThreshold 120 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentAfterMaximumDuration(): void + { + $milliseconds = 170; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @slowThreshold 120 + * + * @maximumDuration 180 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromMaximumDurationAnnotationWhenSlowThresholdAnnotationIsPresentBeforeMaximumDuration(): void + { + $milliseconds = 200; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 + * + * @slowThreshold 3.14 + */ + public function testSleeperSleepsWithDocBlockWithSlowThresholdAnnotationWhereValueIsNotAnInt(): void + { + $milliseconds = 40; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 + * + * @slowThreshold 100 + */ + public function testSleeperSleepsShorterThanMaximumDurationFromSlowThresholdAnnotation(): void + { + $milliseconds = 80; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } + + /** + * @see https://github.com/johnkary/phpunit-speedtrap/blob/1.0/src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php#L309-L331 + * + * @slowThreshold 200 + */ + public function testSleeperSleepsLongerThanMaximumDurationFromSlowThresholdAnnotation(): void + { + $milliseconds = 220; + + $sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds); + + $sleeper->sleep(); + + self::assertSame($milliseconds, $sleeper->milliseconds()); + } +} diff --git a/test/EndToEnd/Version9/MaximumDuration/Fifty/phpunit.xml b/test/EndToEnd/Version9/MaximumDuration/Fifty/phpunit.xml new file mode 100644 index 00000000..cbee0a81 --- /dev/null +++ b/test/EndToEnd/Version9/MaximumDuration/Fifty/phpunit.xml @@ -0,0 +1,36 @@ + + + + + + + 50 + + + + + + + + . + + + diff --git a/test/EndToEnd/Version9/MaximumDuration/Fifty/test.phpt b/test/EndToEnd/Version9/MaximumDuration/Fifty/test.phpt new file mode 100644 index 00000000..b1208b13 --- /dev/null +++ b/test/EndToEnd/Version9/MaximumDuration/Fifty/test.phpt @@ -0,0 +1,35 @@ +--TEST-- +Configuring "maximum-duration" parameter to 50 milliseconds +--FILE-- + + + + + . + + +