Download the PHP package ergebnis/phpunit-slow-test-detector without Composer
On this page you can find all versions of the php package ergebnis/phpunit-slow-test-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpunit-slow-test-detector
phpunit-slow-test-detector
This project provides a composer package and a Phar archive with an extension for detecting slow tests in phpunit/phpunit.
Example
After installing, configuring, and bootstrapping the extension, when running your tests with phpunit/phpunit, the extension will report slow tests:
Compatibility
The extension is compatible with the following versions of phpunit/phpunit:
phpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0phpunit/phpunit:^9.0.0phpunit/phpunit:^8.5.19phpunit/phpunit:^7.5.0phpunit/phpunit:^6.5.0
Installation
Installation with composer
Run
to install ergebnis/phpunit-slow-test-detector as a composer package.
Installation as Phar
Download phpunit-slow-test-detector.phar from the latest release.
Usage
Bootstrapping the extension
Before the extension can detect slow tests in phpunit/phpunit, you need to bootstrap it. The bootstrapping mechanism depends on the version of phpunit/phpunit you are using.
Bootstrapping the extension as a composer package
To bootstrap the extension as a composer package when using
phpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0
adjust your phpunit.xml configuration file and configure the
extensionselement onphpunit/phpunit:^13.0.0extensionselement onphpunit/phpunit:^12.0.0extensionselement onphpunit/phpunit:^11.0.0extensionselement onphpunit/phpunit:^10.0.0
To bootstrap the extension as a composer package when using
phpunit/phpunit:^9.0.0phpunit/phpunit:^8.5.19phpunit/phpunit:^7.5.0
adjust your phpunit.xml configuration file and configure the
extensionselement onphpunit/phpunit:^9.0.0extensionselement onphpunit/phpunit:^8.5.19extensionselement onphpunit/phpunit:^7.5.0
To bootstrap the extension as a composer package when using
phpunit/phpunit:^6.5.0
adjust your phpunit.xml configuration file and configure the
Bootstrapping the extension as a PHAR
To bootstrap the extension as a PHAR when using
phpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0
adjust your phpunit.xml configuration file and configure the
extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^13.0.0extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^12.0.0extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^11.0.0extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^10.0.0
To bootstrap the extension as a PHAR when using
phpunit/phpunit:^9.0.0phpunit/phpunit:^8.5.19phpunit/phpunit:^7.5.0
adjust your phpunit.xml configuration file and configure the
extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^9.0.0extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^8.5.19extensionsDirectoryattribute and theextensionselement onphpunit/phpunit:^7.5.0
Configuring the extension
You can configure the extension with the following options in your phpunit.xml configuration file:
github-actions-annotations, one ofauto,true, orfalse, whether the extension additionally emits slow tests as GitHub Actions annotations, defaults tofalse(see Emitting GitHub Actions annotations)maximum-count, anint, the maximum count of slow test that should be reported, defaults to10maximum-duration, anint, the maximum duration in milliseconds for a test before the extension considers it as a slow test, defaults to500maximum-width, anintof at least80ormax, the maximum width in columns of the table of slow tests, wheremaxdetects the width of the terminal (and uses80for narrower terminals); test descriptions that do not fit are truncated in the middle, defaults to no truncation at allstderr, abool, directs the slow test report output tostderr, defaults tofalse, only available onphpunit/phpunit:^6.5.0,phpunit/phpunit:^7.5.0,phpunit/phpunit:^8.5.19, andphpunit/phpunit:^9.0.0(onphpunit/phpunit:^10.0.0and later, the extension automatically respects thestderrconfigurationphpunit/phpunit)
The configuration mechanism depends on the version of phpunit/phpunit you are using.
Configuring the extension
To configure the extension when using
phpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0
adjust your phpunit.xml configuration file and configure one or more
parameterelements onphpunit/phpunit:^13.0.0parameterelements onphpunit/phpunit:^12.0.0parameterelements onphpunit/phpunit:^11.0.0parameterelements onphpunit/phpunit:^10.0.0
The following example configures the maximum count of slow tests to three, the maximum duration for all tests to 250 milliseconds, and the maximum width of the slow test report to the width of the terminal:
To configure the extension when using
phpunit/phpunit:^9.0.0phpunit/phpunit:^8.5.19phpunit/phpunit:^7.5.0
adjust your phpunit.xml configuration file and configure the
argumentselement onphpunit/phpunit:^9.0.0argumentselement onphpunit/phpunit:^8.5.19argumentselement onphpunit/phpunit:^7.5.0
The following example configures the maximum count of slow tests to three, the maximum duration for all tests to 250 milliseconds, the maximum width of the slow test report to the width of the terminal, and directs the slow test report output to stderr:
To configure the extension when using
phpunit/phpunit:^6.5.0
adjust your phpunit.xml configuration file and configure the
The following example configures the maximum count of slow tests to three, the maximum duration for all tests to 250 milliseconds, the maximum width of the slow test report to the width of the terminal, and directs the slow test report output to stderr:
Emitting GitHub Actions annotations
When the extension detects slow tests, it can additionally emit them as GitHub Actions annotations, so that they show up in the summary of a workflow run.
The extension prints one warning workflow command per reported slow test, to the same stream as the slow test report, for example:
This is disabled by default. You can enable it with the github-actions-annotations parameter:
false(default) never emits annotationsautoemits annotations only when the environment variableGITHUB_ACTIONShas the valuetrue, which GitHub Actions sets for every step; any other value, including an empty one, does not count, so running the tests locally is not affectedtruealways emits annotations
The following example enables GitHub Actions annotations when running on GitHub Actions and using phpunit/phpunit:^10.0.0 and later:
When using phpunit/phpunit:^6.5.0, phpunit/phpunit:^7.5.0, phpunit/phpunit:^8.5.19, or phpunit/phpunit:^9.0.0, configure the github-actions-annotations element in the arguments element:
The number of annotations follows the maximum-count parameter. Note that GitHub Actions shows at most 10 warning annotations per step (a single run of phpunit) and 50 per job (across all of its steps), so annotations beyond that do not appear in the summary of a workflow run.
Configuring the maximum duration per test case
You can configure the maximum duration for a single test case with
- an
Attribute\MaximumDurationattribute when usingphpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0
- a
@maximumDurationannotation in the DocBlock when usingphpunit/phpunit:^9.0.0phpunit/phpunit:^8.5.19phpunit/phpunit:^7.5.0phpunit/phpunit:^6.5.0
- a
@slowThresholdannotation in the DocBlock when usingphpunit/phpunit:^9.0.0phpunit/phpunit:^8.5.19phpunit/phpunit:^7.5.0phpunit/phpunit:^6.5.0
The following example configures the maximum durations for single test cases to 5,000 ms, 4,000 ms, and 3,000 ms:
[!NOTE]
Support for the
@slowThresholdannotation exists only to help you move fromjohnkary/phpunit-speedtrap. It will be deprecated and removed in the near future.
Understanding measured test durations
Understanding measured test durations when using the new event system
When using
phpunit/phpunit:^13.0.0phpunit/phpunit:^12.0.0phpunit/phpunit:^11.0.0phpunit/phpunit:^10.0.0
the extension uses the new event system of phpunit/phpunit, and measures the duration between the points in time when the PHPUnit\Event\Test\PreparationStarted and PHPUnit\Event\Test\Finished are emitted.
Understanding measured test durations when using the hooks event system
When using
phpunit/phpunit:^9.0.0phpunit/phpunit:^8.5.19phpunit/phpunit:^7.5.0phpunit/phpunit:^6.5.0
the extension uses the hooks event system of phpunit/phpunit, and measures the duration that is passed to the PHPUnit\Runner\AfterTestHook. This is the duration of invoking PHPUnit\Framework\TestCase::runBare() and more.
[!NOTE] Because of this behavior, the measured test durations can and will vary depending on the order in which
phpunit/phpunitexecutes tests.
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
PHP Version Support Policy
This project currently supports the following PHP versions:
- PHP 7.4 (has reached its end of life on November 28, 2022)
- PHP 8.0 (has reached its end of life on November 26, 2023)
- PHP 8.1 (has reached its end of life on December 31, 2025)
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Credits
This package is inspired by johnkary/phpunit-speedtrap, originally licensed under MIT by John Kary.
Social
Follow @localheinz and @ergebnis on X.
All versions of phpunit-slow-test-detector with dependencies
ext-mbstring Version *
phpunit/phpunit Version ^6.5.0 || ^7.5.0 || ^8.5.19 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0