{"id":13607966,"url":"https://github.com/johnkary/phpunit-speedtrap","last_synced_at":"2025-05-14T17:07:08.577Z","repository":{"id":13840599,"uuid":"16537617","full_name":"johnkary/phpunit-speedtrap","owner":"johnkary","description":"Reports on slow-running tests in your PHPUnit test suite","archived":false,"fork":false,"pushed_at":"2023-05-22T06:44:38.000Z","size":167,"stargazers_count":783,"open_issues_count":27,"forks_count":62,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-13T02:00:05.947Z","etag":null,"topics":["phpunit","phpunit-listener"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnkary.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-02-05T07:02:18.000Z","updated_at":"2025-03-01T01:52:46.000Z","dependencies_parsed_at":"2024-02-25T00:43:10.052Z","dependency_job_id":null,"html_url":"https://github.com/johnkary/phpunit-speedtrap","commit_stats":{"total_commits":153,"total_committers":25,"mean_commits":6.12,"dds":0.3594771241830066,"last_synced_commit":"a05623c3e211a857a546ae5bab19dca8d3d378f9"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnkary%2Fphpunit-speedtrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnkary%2Fphpunit-speedtrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnkary%2Fphpunit-speedtrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnkary%2Fphpunit-speedtrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnkary","download_url":"https://codeload.github.com/johnkary/phpunit-speedtrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254190396,"owners_count":22029632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["phpunit","phpunit-listener"],"created_at":"2024-08-01T19:01:23.172Z","updated_at":"2025-05-14T17:07:08.552Z","avatar_url":"https://github.com/johnkary.png","language":"PHP","readme":"# phpunit-speedtrap\n\n[![Integrate](https://github.com/johnkary/phpunit-speedtrap/workflows/Integrate/badge.svg?branch=master)](https://github.com/johnkary/phpunit-speedtrap/actions)\n\nSpeedTrap reports on slow-running PHPUnit tests right in the console.\n\nMany 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.\n\nSpeedTrap 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.\n\n![Screenshot of terminal using SpeedTrap](https://user-images.githubusercontent.com/135607/196077193-ba9e5f95-91ef-4655-88a5-93bb49007a67.png)\n\n## Installation\n\nSpeedTrap is installed using [Composer](http://getcomposer.org). Add it as a `require-dev` dependency:\n\n    composer require --dev johnkary/phpunit-speedtrap\n\n\n## Usage\n\nEnable with all defaults by adding the following code to your project's `phpunit.xml` file:\n \n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n...\n    \u003cextensions\u003e\n        \u003cextension class=\"JohnKary\\PHPUnit\\Extension\\SpeedTrap\" /\u003e\n    \u003c/extensions\u003e\n\u003c/phpunit\u003e\n```\n\nNow 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.\n\n## Config Parameters\n\nSpeedTrap also supports these parameters:\n\n* **slowThreshold** - Number of milliseconds when a test is considered \"slow\" (Default: 500ms)\n* **reportLength** - Number of slow tests included in the report (Default: 10 tests)\n\nEach parameter is set in `phpunit.xml`:\n\n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n    \u003c!-- ... other suite configuration here ... --\u003e\n\n    \u003cextensions\u003e\n        \u003cextension class=\"JohnKary\\PHPUnit\\Extension\\SpeedTrap\"\u003e\n            \u003carguments\u003e\n                \u003carray\u003e\n                    \u003celement key=\"slowThreshold\"\u003e\n                        \u003cinteger\u003e500\u003c/integer\u003e\n                    \u003c/element\u003e\n                    \u003celement key=\"reportLength\"\u003e\n                        \u003cinteger\u003e10\u003c/integer\u003e\n                    \u003c/element\u003e\n                \u003c/array\u003e\n            \u003c/arguments\u003e\n        \u003c/extension\u003e\n    \u003c/extensions\u003e\n\u003c/phpunit\u003e\n```\n\n## Custom slowness threshold per-test case\n\nSome 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.\n\nThe 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.\n\n```php\nclass SomeTestCase extends PHPUnit\\Framework\\TestCase\n{\n    /**\n     * @slowThreshold 5000\n     */\n    public function testLongRunningProcess()\n    {\n        // Code that takes a longer time to execute\n    }\n}\n```\n\nSetting `@slowThreshold 0` will never report that test as slow.\n\n## Disable slowness profiling using an environment variable\n\nSpeedTrap profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEEDTRAP` can enable or disable the extension:\n\n    $ PHPUNIT_SPEEDTRAP=\"disabled\" ./vendor/bin/phpunit\n\n#### Use case: Disable profiling in development, but profile with Travis CI\n\nTravis CI is popular for running tests in the cloud after pushing new code to a repository.\n\nStep 1) Enable SpeedTrap in phpunit.xml, but set `PHPUNIT_SPEEDTRAP=\"disabled\"` to disable profiling when running tests.\n\n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n...\n    \u003cphp\u003e\n        \u003cenv name=\"PHPUNIT_SPEEDTRAP\" value=\"disabled\" /\u003e\n    \u003c/php\u003e\n\n    \u003cextensions\u003e\n        \u003cextension class=\"JohnKary\\PHPUnit\\Extension\\SpeedTrap\" /\u003e\n    \u003c/extensions\u003e\n\u003c/phpunit\u003e\n```\n\nStep 2) Configure `.travis.yml` with `PHPUNIT_SPEEDTRAP=\"enabled\"` to profile for slow tests when running on Travis CI:\n\n```yaml\nlanguage: php\n\nphp:\n  - 7.3\n\nenv:\n  - PHPUNIT_SPEEDTRAP=\"enabled\"\n```\n\nStep 3) View the Travis CI build output and read the slowness report printed in the console.\n\n[Travis CI Documentation - Environment Variables](https://docs.travis-ci.com/user/environment-variables)\n\n#### Use case: Enable profiling in development, but disable with Travis CI\n\nStep 1) Enable SpeedTrap in phpunit.xml. The slowness report will output during all test suite executions.\n\n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n...\n    \u003cextensions\u003e\n        \u003cextension class=\"JohnKary\\PHPUnit\\Extension\\SpeedTrap\" /\u003e\n    \u003c/extensions\u003e\n\u003c/phpunit\u003e\n```\n\nStep 2) Configure `.travis.yml` with `PHPUNIT_SPEEDTRAP=\"disabled\"` to turn off profiling when running on Travis CI:\n\n```yaml\nlanguage: php\n\nphp:\n  - 7.3\n\nenv:\n  - PHPUNIT_SPEEDTRAP=\"disabled\"\n```\n\nStep 3) View the Travis CI build output and confirm the slowness report is not printed in the console.\n\n#### Use case: Only enable SpeedTrap on demand via command-line\n\nUseful when you only want to profile slow tests once in a while.\n\nStep 1) Setup phpunit.xml to enable SpeedTrap, but disable slowness profiling by setting `PHPUNIT_SPEEDTRAP=\"disabled\"` like this:\n\n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n...\n    \u003cphp\u003e\n        \u003cenv name=\"PHPUNIT_SPEEDTRAP\" value=\"disabled\" /\u003e\n    \u003c/php\u003e\n\n    \u003cextensions\u003e\n        \u003cextension class=\"JohnKary\\PHPUnit\\Extension\\SpeedTrap\" /\u003e\n    \u003c/extensions\u003e\n\u003c/phpunit\u003e\n```\n\nStep 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:\n\n```bash\n$ PHPUNIT_SPEEDTRAP=enabled ./vendor/bin/phpunit\n```\n\n## Using with Symfony Framework\n\n[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/`\n\nsymfony/phpunit-bridge allows environment variable `SYMFONY_PHPUNIT_REQUIRE` to define additional dependencies while installing phpunit.\n\nThe easiest way to set environment variables for the script `simple-phpunit` is via phpunit.xml.dist:\n\n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n    \u003cphp\u003e\n        \u003cenv name=\"SYMFONY_PHPUNIT_REQUIRE\" value=\"johnkary/phpunit-speedtrap:^4\"/\u003e\n        \u003cenv name=\"SYMFONY_PHPUNIT_VERSION\" value=\"9\"/\u003e\n    \u003c/php\u003e\n\n    \u003cextensions\u003e\n        \u003cextension class=\"JohnKary\\PHPUnit\\Extension\\SpeedTrap\" /\u003e\n    \u003c/extensions\u003e\n\u003c/phpunit\u003e\n```\n\nUsing the above example, running `vendor/bin/simple-phpunit` will now install the latest PHPUnit 9 and require the latest phpunit-speedtrap v4.\n\n## Development\n\nFollow these steps to add new features or develop your own fork:\n\n```\n# Get source code (or replace with your fork URL)\n$ git checkout https://github.com/johnkary/phpunit-speedtrap.git phpunit-speedtrap\n\n# Install dev dependencies\n$ cd phpunit-speedtrap\n$ composer install\n\n# Run test suite to verify code runs as expected\n$ vendor/bin/phpunit\n```\n\n## Inspiration\n\nSpeedTrap was inspired by [RSpec's](https://github.com/rspec/rspec) `--profile` option that displays feedback about slow tests.\n\n## License\n\nphpunit-speedtrap is available under the MIT License.\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnkary%2Fphpunit-speedtrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnkary%2Fphpunit-speedtrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnkary%2Fphpunit-speedtrap/lists"}