PHPackages                             johnkary/phpunit-speedtrap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. johnkary/phpunit-speedtrap

ActiveLibrary[Testing &amp; Quality](/categories/testing)

johnkary/phpunit-speedtrap
==========================

Find and report on slow tests in your PHPUnit test suite

v4.0.1(3y ago)78337.2M↑17.6%61[18 issues](https://github.com/johnkary/phpunit-speedtrap/issues)[9 PRs](https://github.com/johnkary/phpunit-speedtrap/pulls)20MITPHPPHP &gt;=7.1CI failing

Since Mar 21Pushed 2y ago12 watchersCompare

[ Source](https://github.com/johnkary/phpunit-speedtrap)[ Packagist](https://packagist.org/packages/johnkary/phpunit-speedtrap)[ Docs](https://github.com/johnkary/phpunit-speedtrap)[ RSS](/packages/johnkary-phpunit-speedtrap/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (22)Used By (20)

phpunit-speedtrap
=================

[](#phpunit-speedtrap)

[![Integrate](https://github.com/johnkary/phpunit-speedtrap/workflows/Integrate/badge.svg?branch=master)](https://github.com/johnkary/phpunit-speedtrap/actions)

SpeedTrap reports on slow-running PHPUnit tests right in the console.

Many factors affect test execution time. A test not properly isolated from variable latency (database, network, etc.) and even basic load on the test machine will cause test execution times to fluctuate.

SpeedTrap helps **identify slow tests** but cannot explain **why** those tests are slow. Consider using [Blackfire.io](https://blackfire.io) to profile the test suite to specifically identify slow code.

[![Screenshot of terminal using SpeedTrap](https://user-images.githubusercontent.com/135607/196077193-ba9e5f95-91ef-4655-88a5-93bb49007a67.png)](https://user-images.githubusercontent.com/135607/196077193-ba9e5f95-91ef-4655-88a5-93bb49007a67.png)

Installation
------------

[](#installation)

SpeedTrap is installed using [Composer](http://getcomposer.org). Add it as a `require-dev` dependency:

```
composer require --dev johnkary/phpunit-speedtrap

```

Usage
-----

[](#usage)

Enable with all defaults by adding the following code to your project's `phpunit.xml` file:

```

...

```

Now run the test suite. If one or more test executions exceed the slowness threshold (500ms by default), SpeedTrap will report on those tests in the console after all tests have completed.

Config Parameters
-----------------

[](#config-parameters)

SpeedTrap also supports these parameters:

- **slowThreshold** - Number of milliseconds when a test is considered "slow" (Default: 500ms)
- **reportLength** - Number of slow tests included in the report (Default: 10 tests)

Each parameter is set in `phpunit.xml`:

```

                        500

                        10

```

Custom slowness threshold per-test case
---------------------------------------

[](#custom-slowness-threshold-per-test-case)

Some projects have a few complex tests that take a long time to run. It is possible to set a different slowness threshold for individual test cases.

The annotation `@slowThreshold` can set a custom slowness threshold for each test case. This number may be higher or lower than the default threshold and is used instead of the default threshold for that specific test.

```
class SomeTestCase extends PHPUnit\Framework\TestCase
{
    /**
     * @slowThreshold 5000
     */
    public function testLongRunningProcess()
    {
        // Code that takes a longer time to execute
    }
}
```

Setting `@slowThreshold 0` will never report that test as slow.

Disable slowness profiling using an environment variable
--------------------------------------------------------

[](#disable-slowness-profiling-using-an-environment-variable)

SpeedTrap profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEEDTRAP` can enable or disable the extension:

```
$ PHPUNIT_SPEEDTRAP="disabled" ./vendor/bin/phpunit

```

#### Use case: Disable profiling in development, but profile with Travis CI

[](#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 SpeedTrap in phpunit.xml, but set `PHPUNIT_SPEEDTRAP="disabled"` to disable profiling when running tests.

```

...

```

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](https://docs.travis-ci.com/user/environment-variables)

#### Use case: Enable profiling in development, but disable with Travis CI

[](#use-case-enable-profiling-in-development-but-disable-with-travis-ci)

Step 1) Enable SpeedTrap in phpunit.xml. The slowness report will output during all test suite executions.

```

...

```

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 SpeedTrap on demand via command-line

[](#use-case-only-enable-speedtrap-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 SpeedTrap, but disable slowness profiling by setting `PHPUNIT_SPEEDTRAP="disabled"` like this:

```

...

```

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
```

Using with Symfony Framework
----------------------------

[](#using-with-symfony-framework)

[Symfony Framework](https://symfony.com/) comes with package [symfony/phpunit-bridge](https://packagist.org/packages/symfony/phpunit-bridge) that installs its own version of PHPUnit and **ignores** what is defined in your project's composer.json or composer.lock file. See the PHPUnit versions it installs with command `ls vendor/bin/.phpunit/`

symfony/phpunit-bridge allows environment variable `SYMFONY_PHPUNIT_REQUIRE` to define additional dependencies while installing phpunit.

The easiest way to set environment variables for the script `simple-phpunit` is via phpunit.xml.dist:

```

```

Using the above example, running `vendor/bin/simple-phpunit` will now install the latest PHPUnit 9 and require the latest phpunit-speedtrap v4.

Development
-----------

[](#development)

Follow these steps to add new features or develop your own fork:

```
# Get source code (or replace with your fork URL)
$ git checkout https://github.com/johnkary/phpunit-speedtrap.git phpunit-speedtrap

# Install dev dependencies
$ cd phpunit-speedtrap
$ composer install

# Run test suite to verify code runs as expected
$ vendor/bin/phpunit

```

Inspiration
-----------

[](#inspiration)

SpeedTrap was inspired by [RSpec's](https://github.com/rspec/rspec) `--profile` option that displays feedback about slow tests.

License
-------

[](#license)

phpunit-speedtrap is available under the MIT License.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity72

Solid adoption and visibility

Community45

Growing community involvement

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 74.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~184 days

Recently: every ~244 days

Total

16

Last Release

1310d ago

Major Versions

v1.0.2 → v2.0.0-BETA12017-03-17

1.1.x-dev → v2.0.02017-12-06

v2.0.0 → v3.0.02018-02-24

v3.3.0 → v4.0.02021-05-03

PHP version history (4 changes)v1.0.0PHP &gt;=5.3.0

v1.0.2PHP &gt;=5.6

v2.0.0-BETA1PHP &gt;=7.0

v3.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/135607?v=4)[John Kary](/maintainers/johnkary)[@johnkary](https://github.com/johnkary)

---

Top Contributors

[![johnkary](https://avatars.githubusercontent.com/u/135607?v=4)](https://github.com/johnkary "johnkary (142 commits)")[![dxops](https://avatars.githubusercontent.com/u/1804871?v=4)](https://github.com/dxops "dxops (11 commits)")[![luispabon](https://avatars.githubusercontent.com/u/6388823?v=4)](https://github.com/luispabon "luispabon (5 commits)")[![Engerim](https://avatars.githubusercontent.com/u/1322557?v=4)](https://github.com/Engerim "Engerim (5 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (5 commits)")[![SergeyZ](https://avatars.githubusercontent.com/u/92912310?v=4)](https://github.com/SergeyZ "SergeyZ (5 commits)")[![pscheit](https://avatars.githubusercontent.com/u/488189?v=4)](https://github.com/pscheit "pscheit (2 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (2 commits)")[![MGatner](https://avatars.githubusercontent.com/u/17572847?v=4)](https://github.com/MGatner "MGatner (1 commits)")[![mihaeu](https://avatars.githubusercontent.com/u/2168701?v=4)](https://github.com/mihaeu "mihaeu (1 commits)")[![mvorisek](https://avatars.githubusercontent.com/u/2228672?v=4)](https://github.com/mvorisek "mvorisek (1 commits)")[![PascalThesing](https://avatars.githubusercontent.com/u/14017436?v=4)](https://github.com/PascalThesing "PascalThesing (1 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![vincentlaurier](https://avatars.githubusercontent.com/u/157579630?v=4)](https://github.com/vincentlaurier "vincentlaurier (1 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (1 commits)")[![duncan3dc](https://avatars.githubusercontent.com/u/546811?v=4)](https://github.com/duncan3dc "duncan3dc (1 commits)")[![fain182](https://avatars.githubusercontent.com/u/5879?v=4)](https://github.com/fain182 "fain182 (1 commits)")[![hkdobrev](https://avatars.githubusercontent.com/u/506129?v=4)](https://github.com/hkdobrev "hkdobrev (1 commits)")[![jakeasmith](https://avatars.githubusercontent.com/u/234832?v=4)](https://github.com/jakeasmith "jakeasmith (1 commits)")

---

Tags

phpunitphpunit-listenerphpunitprofileslow

### Embed Badge

![Health badge](/badges/johnkary-phpunit-speedtrap/health.svg)

```
[![Health](https://phpackages.com/badges/johnkary-phpunit-speedtrap/health.svg)](https://phpackages.com/packages/johnkary-phpunit-speedtrap)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69617.9M510](/packages/spatie-phpunit-snapshot-assertions)[phpspec/prophecy-phpunit

Integrating the Prophecy mocking library in PHPUnit test cases

19454.9M1.4k](/packages/phpspec-prophecy-phpunit)[yoast/phpunit-polyfills

Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests

18438.5M841](/packages/yoast-phpunit-polyfills)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
