{"id":33993639,"url":"https://github.com/hughsaffar/laravel-test-trap","last_synced_at":"2025-12-13T07:27:18.095Z","repository":{"id":48281300,"uuid":"284718384","full_name":"hughsaffar/laravel-test-trap","owner":"hughsaffar","description":"Laravel Test Trap will help you to trap tests that take longer than what you expect and find problematic SQL queries in your tests.","archived":false,"fork":false,"pushed_at":"2023-06-28T15:21:11.000Z","size":70,"stargazers_count":18,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-09T23:49:06.719Z","etag":null,"topics":["laravel","profiling","testing"],"latest_commit_sha":null,"homepage":"https://github.com/hughsaffar/laravel-test-trap","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/hughsaffar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2020-08-03T14:13:17.000Z","updated_at":"2024-02-10T18:08:13.000Z","dependencies_parsed_at":"2022-09-07T17:41:29.010Z","dependency_job_id":null,"html_url":"https://github.com/hughsaffar/laravel-test-trap","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/hughsaffar/laravel-test-trap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsaffar%2Flaravel-test-trap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsaffar%2Flaravel-test-trap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsaffar%2Flaravel-test-trap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsaffar%2Flaravel-test-trap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hughsaffar","download_url":"https://codeload.github.com/hughsaffar/laravel-test-trap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hughsaffar%2Flaravel-test-trap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27701999,"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","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["laravel","profiling","testing"],"created_at":"2025-12-13T07:27:17.632Z","updated_at":"2025-12-13T07:27:18.087Z","avatar_url":"https://github.com/hughsaffar.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Speed and SQL trap for Laravel Tests\n\n[![PHP Version](https://img.shields.io/packagist/php-v/hughsaffar/laravel-test-trap)](https://packagist.org/packages/spatie/laravel-test-trap)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/hughsaffar/laravel-test-trap)](https://packagist.org/packages/hughsaffar/laravel-test-trap)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/hughsaffar/laravel-test-trap/Tests)](https://github.com/hughsaffar/laravel-test-trap/actions?query=workflow%3ATests+branch%3Amaster)\n[![License](https://img.shields.io/packagist/l/hughsaffar/laravel-test-trap)](https://packagist.org/packages/hughsaffar/laravel-test-trap)\n\n![Screenshot of terminal using Laravel Test Trap](https://i.imgur.com/a6hoowt.png)\n\nLaravel Test Trap will help you trap any slow tests or when a SQL query is slow or runs multiple times. \nLaravel Test Trap is inspired by [phpunit-speedtrap](https://github.com/johnkary/phpunit-speedtrap) and is tailored to be used in Laravel applications. \n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require --dev hughsaffar/laravel-test-trap\n```\n\nYou can publish the config file with:\n```bash\nphp artisan vendor:publish --provider=\"TestTrap\\TestTrapServiceProvider\" --tag=\"config\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n    'ignore_migrations_queries' =\u003e env('TEST_TRAP_IGNORE_MIGRATIONS_QUERIES', true),\n    'environment_name' =\u003e env('TEST_TRAP_ENVIRONMENT', 'testing'),\n];\n```\n\n- By setting `ignore_migrations_queries` to `true`, Laravel Test Trap will not log any related queries to the migrations. This is useful if you are using `RefreshDatabase` trait on your tests. However, if you are running migration manually for your test database you need to set the value to `false`;\n- By default, Laravel Test Trap will only log queries when the application is running on `testing` environment. If your application has a different name for testing environment you may override it by changing `environment_name` value.  \n\n## Usage\n\nLaravel Test Trap comes with an PHPUnit extension class that you need to add to your `phpunit.xml`.\n\n``` xml\n\u003cextensions\u003e\n    \u003cextension class=\"TestTrap\\TestTrapExtension\"\u003e\n        \u003carguments\u003e\n            \u003carray\u003e\n                \u003celement key=\"speed\"\u003e\n                    \u003cdouble\u003e500\u003c/double\u003e\n                \u003c/element\u003e\n                \u003celement key=\"queryCalled\"\u003e\n                    \u003cinteger\u003e10\u003c/integer\u003e\n                \u003c/element\u003e\n                \u003celement key=\"querySpeed\"\u003e\n                    \u003cdouble\u003e1000\u003c/double\u003e\n                \u003c/element\u003e\n            \u003c/array\u003e\n        \u003c/arguments\u003e\n    \u003c/extension\u003e\n\u003c/extensions\u003e\n```\n\nIn this example we ask Test Trap to report any tests that:\n\n- Take more than 500ms to run\n- Or run a single query more than 10 times in a test\n- Or a query takes more than a second (1000ms) to run\n\n### Disable Laravel Test Trap\n\nIf you do not want Laravel Test Trap to always run with your tests, you can simply disable it by adding an environment variable to your `phpunit.xml` file:\n\n```xml\n\u003cphp\u003e\n   ...\n   \u003cserver name=\"TEST_TRAP_DISABLE\" value=\"true\"/\u003e\n   ...\n\u003c/php\u003e\n```\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email hs@houmaan.ca instead of using the issue tracker.\n\n## Credits\n\n- [Hugh Saffar](https://github.com/hughsaffar)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhughsaffar%2Flaravel-test-trap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhughsaffar%2Flaravel-test-trap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhughsaffar%2Flaravel-test-trap/lists"}