From 0a169617e7651b89c1d7abc607337b41ddd30ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 5 Dec 2023 12:23:50 +0100 Subject: [PATCH] Fix: Adjust documentation --- README.md | 108 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 01246b42..44a560df 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The extension is compatible with the following versions of `phpunit/phpunit`: ## Installation -### Composer +### Installation with `composer` Run @@ -30,17 +30,42 @@ Run composer require --dev ergebnis/phpunit-slow-test-detector ``` -to install `ergebnis/phpunit-slow-test-detector` as a `composer` package. +to install `ergebnis/phpunit-slow-test-detector` as a `composer` package when using `phpunit/phpunit:^8.5.19`, `phpunit/phpunit:^9.0.0`, or `phpunit/phpunit:^10.0.0`. -### Phar +### Installation as Phar -Download `phpunit-slow-test-detector.phar` from the [latest release](https://github.com/ergebnis/phpunit-slow-test-detector/releases/latest). +Download `phpunit-slow-test-detector.phar` from the [latest release](https://github.com/ergebnis/phpunit-slow-test-detector/releases/latest) when using `phpunit/phpunit:^10.0.0`. ## Usage -### Bootstrapping the extension as a `composer` package +### Bootstrapping the extension -To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/9.6/configuration.html#the-extensions-element): +Before the extension can detect slow tests in `phpunit/phpunit`, you need to bootstrap it. + +#### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^8.5.19` + +To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^8.5.19`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/8.5/configuration.html#the-extensions-element): + +```diff + ++ ++ ++ + + + test/Unit/ + + + +``` + +#### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^9.0.0` + +To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^9.0.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 ``` +#### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^10.0.0` + To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^10.0.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 @@ -78,7 +105,7 @@ To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^ ``` -### Bootstrapping the extension as a PHAR +#### Bootstrapping the extension as a PHAR when using `phpunit/phpunit:^10.0.0` To bootstrap the extension as a PHAR when using `phpunit/phpunit:^10.0.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): @@ -102,12 +129,14 @@ To bootstrap the extension as a PHAR when using `phpunit/phpunit:^10.0.0`, adjus ### Configuring the extension -You can configure the extension with the following parameters in your `phpunit.xml` configuration file: +You can configure the extension with the following options in your `phpunit.xml` configuration file: -- `maximum-count`, an `int`, the maximum count of slow test that should be listed, defaults to `10` -- `maximum-duration`, an `int`, the maximum duration in milliseconds for all tests, defaults to `500` +- `maximum-count`, an `int`, the maximum count of slow test that should be reported, defaults to `10` +- `maximum-duration`, an `int`, the maximum duration in milliseconds for a test before the extension considers it as a slow test, defaults to `500` -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:^10.0.0`: +#### Configuring the extension when using `phpunit/phpunit:^8.5.19` + +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:^8.5.19`: ```diff -- -+ -+ -+ -+ +- ++ ++ ++ ++ ++ 3 ++ ++ ++ 250 ++ ++ ++ ++ @@ -130,7 +167,9 @@ The following example configures the maximum count of slow tests to three, and t ``` -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:^8.5.19` or `phpunit/phpunit:^9.0.0`: +#### Configuring the extension when using `phpunit/phpunit:^9.0.0` + +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.0.0`: ```diff ``` +#### Configuring the extension when using `phpunit/phpunit:^10.0.0` + +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:^10.0.0`: + +```diff + + +- ++ ++ ++ ++ + + + + test/Unit/ + + + +``` + #### Configuring the maximum duration per test case You can configure the maximum duration for a single test case with -- an `Attribute\MaximumDuration` attribute -- a `@maximumDuration` annotation in the DocBlock -- a `@slowThreshold` annotation in the DocBlock +- an `Attribute\MaximumDuration` attribute when using `phpunit/phpunit:^10.0.0` +- a `@maximumDuration` annotation in the DocBlock when using `phpunit/phpunit:^8.5.19` or `phpunit/phpunit:^9.0.0` +- a `@slowThreshold` annotation in the DocBlock when using `phpunit/phpunit:^8.5.19` or `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: @@ -207,9 +271,11 @@ final class ExtraSlowTest extends Framework\TestCase } ``` +Note that support for the `@slowThreshold` will be deprecated and removed in the near future and exists only to help you move from [`johnkary/phpunit-speedtrap`](https://github.com/johnkary/phpunit-speedtrap) + ### Running tests -When you have activated the extension, you can run your tests as usually: +When you have bootstrapped the extension, you can run your tests as usually: ```sh vendor/bin/phpunit