Releases: johnkary/phpunit-speedtrap
v4.0.0
- Changelog (
v3.3.0...v.4.0.0
) - PR #81 Reformat slow test case output for compatibility with PHPUnit --filter option
- PR #82 New option
stopOnSlow
stops execution upon first slow test. Default: false. - PR #84 New annotation option
@slowThreshold 0
disables checks for individual tests. - README documents incompatibility with Symfony Framework
simple-phpunit
This is the last release compatible with PHP < 7.2 and PHPUnit < 8.0. SpeedTrap v5.0.0 will be upgrading to the PHPUnit Extension system instead of the TestListener system.
Despite being a new feature in v4.0.0, the stopOnSlow
configuration will be removed in v5.0.0 because the new PHPUnit Extension system does not support Extensions stopping the test runner.
BC Break: Slowness report changes formatting of slow class names
You may encounter a backwards compatibility break if you programmatically parse the console output from SpeedTrap.
Prior to 4.0 the slowness report displayed the qualified class name in a human-readable format:
1. 800ms to run JohnKary\PHPUnit\Listener\Tests\SomeSlowTest:testWithDataProvider with data set "Rock"
Starting at 4.0 the slowness report displays class names in a format ready to be used with PHPUnit's --filter option by adding slashes to the namespace delimiter and adding a colon between the class and method name:
1. 800ms to run JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"
An individual slow test case can now be re-run by copying and pasting the output into a new command:
vendor/bin/phpunit --filter 'JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"'
Note that PHPUnit uses single quotes for the --filter
option value. See the --filter option documentation for all supported matching patterns.
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