Compatibility with PHPUnit 9.5+ and more
🎊 Version 3.3.0 has been released! 🎊
If you encounter issues please open a new Issue or create a new Discussion.
How do I upgrade?
Version 3.3.0 is backwards compatible with all prior version 3.0 releases. There are no breaking changes.
{
"require": {
"johnkary/phpunit-speedtrap": "^3.3"
}
}$ composer update johnkary/phpunit-speedtrap
Compatibility with PHPUnit 9.5+
Thank you @mvorisek for communicating with Sebastian on the fix and proposing PR #73 fixing the issue. And thank you to everyone upvoting that the fix worked!
New Feature: Disable slowness profiling using an environment variable
SpeedTrapListener profiles for slow tests when enabled in phpunit.xml. But using an environment variable named PHPUNIT_SPEEDTRAP can enable or disable the listener.
$ PHPUNIT_SPEEDTRAP="disabled" ./vendor/bin/phpunit
Use case: Disable profiling in development, but profile with Travis CI
Travis CI is popular for running tests in the cloud after pushing new code to a repository.
Step 1) Enable SpeedTrapListener in phpunit.xml, but set PHPUNIT_SPEEDTRAP="disabled" to disable profiling when running tests.
<phpunit bootstrap="vendor/autoload.php">
...
<php>
<env name="PHPUNIT_SPEEDTRAP" value="disabled" />
</php>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
</phpunit>Step 2) Configure .travis.yml with PHPUNIT_SPEEDTRAP="enabled" to profile for slow tests when running on Travis CI:
language: php
php:
- 7.3
env:
- PHPUNIT_SPEEDTRAP="enabled"Step 3) View the Travis CI build output and read the slowness report printed in the console.
Travis CI Documentation - Environment Variables
Use case: Enable profiling in development, but disable with Travis CI
Step 1) Enable SpeedTrapListener in phpunit.xml. The slowness report will output during all test suite executions.
<phpunit bootstrap="vendor/autoload.php">
...
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
</phpunit>Step 2) Configure .travis.yml with PHPUNIT_SPEEDTRAP="disabled" to turn off profiling when running on Travis CI:
language: php
php:
- 7.3
env:
- PHPUNIT_SPEEDTRAP="disabled"Step 3) View the Travis CI build output and confirm the slowness report is not printed in the console.
Use case: Only enable SpeedTrapListener on demand via command-line
Useful when you only want to profile slow tests once in a while.
Step 1) Setup phpunit.xml to enable SpeedTrapListener, but disable slowness profiling by setting PHPUNIT_SPEEDTRAP="disabled" like this:
<phpunit bootstrap="vendor/autoload.php">
...
<php>
<env name="PHPUNIT_SPEEDTRAP" value="disabled" />
</php>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
</phpunit>Step 2) When executing phpunit from the command-line, enable slowness profiling only for this run by passing the environment variable PHPUNIT_SPEEDTRAP="enabled" like this:
$ PHPUNIT_SPEEDTRAP=enabled ./vendor/bin/phpunit