PHPackages                             hughsaffar/laravel-test-trap - 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. hughsaffar/laravel-test-trap

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

hughsaffar/laravel-test-trap
============================

Laravel Test Trap

1.1.4(3y ago)18406.8k1[1 PRs](https://github.com/hughsaffar/laravel-test-trap/pulls)MITPHPPHP &gt;=7.4CI failing

Since Aug 3Pushed 3y ago2 watchersCompare

[ Source](https://github.com/hughsaffar/laravel-test-trap)[ Packagist](https://packagist.org/packages/hughsaffar/laravel-test-trap)[ Docs](https://github.com/hughsaffar/laravel-test-trap)[ RSS](/packages/hughsaffar-laravel-test-trap/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (7)Dependencies (7)Versions (9)Used By (0)

Speed and SQL trap for Laravel Tests
====================================

[](#speed-and-sql-trap-for-laravel-tests)

[![PHP Version](https://camo.githubusercontent.com/72c0e59db3841e1f0022a513022c6464dd02e79425d6f1d7410dc1af85279966/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f687567687361666661722f6c61726176656c2d746573742d74726170)](https://packagist.org/packages/spatie/laravel-test-trap)[![Latest Version on Packagist](https://camo.githubusercontent.com/975bf004a80c20b69b8fc2c2d0e1ad9f39b4b679fc13d7a149ccb99aa6d59871/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f687567687361666661722f6c61726176656c2d746573742d74726170)](https://packagist.org/packages/hughsaffar/laravel-test-trap)[![GitHub Tests Action Status](https://camo.githubusercontent.com/5a99745c0626b276b41298d7b55b5f20aa1cbb3c7a2600912bbca86926e94dee/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f687567687361666661722f6c61726176656c2d746573742d747261702f5465737473)](https://github.com/hughsaffar/laravel-test-trap/actions?query=workflow%3ATests+branch%3Amaster)[![License](https://camo.githubusercontent.com/baa6450bf46aa0bc10f29288dd0161055844c9df242fbee83ab83231d4a07ed3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f687567687361666661722f6c61726176656c2d746573742d74726170)](https://packagist.org/packages/hughsaffar/laravel-test-trap)

[![Screenshot of terminal using Laravel Test Trap](https://camo.githubusercontent.com/c9681bd7fff08cd91f6641d6cf35e5ad30e11742d5ae7c91c660e5c2c5c32052/68747470733a2f2f692e696d6775722e636f6d2f6136686f6f77742e706e67)](https://camo.githubusercontent.com/c9681bd7fff08cd91f6641d6cf35e5ad30e11742d5ae7c91c660e5c2c5c32052/68747470733a2f2f692e696d6775722e636f6d2f6136686f6f77742e706e67)

Laravel Test Trap will help you trap any slow tests or when a SQL query is slow or runs multiple times. Laravel Test Trap is inspired by [phpunit-speedtrap](https://github.com/johnkary/phpunit-speedtrap) and is tailored to be used in Laravel applications.

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

[](#installation)

You can install the package via composer:

```
composer require --dev hughsaffar/laravel-test-trap
```

You can publish the config file with:

```
php artisan vendor:publish --provider="TestTrap\TestTrapServiceProvider" --tag="config"
```

This is the contents of the published config file:

```
return [
    'ignore_migrations_queries' => env('TEST_TRAP_IGNORE_MIGRATIONS_QUERIES', true),
    'environment_name' => env('TEST_TRAP_ENVIRONMENT', 'testing'),
];
```

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

Usage
-----

[](#usage)

Laravel Test Trap comes with an PHPUnit extension class that you need to add to your `phpunit.xml`.

```

                    500

                    10

                    1000

```

In this example we ask Test Trap to report any tests that:

- Take more than 500ms to run
- Or run a single query more than 10 times in a test
- Or a query takes more than a second (1000ms) to run

### Disable Laravel Test Trap

[](#disable-laravel-test-trap)

If 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:

```

   ...

   ...

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Hugh Saffar](https://github.com/hughsaffar)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% 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 ~176 days

Recently: every ~264 days

Total

7

Last Release

1100d ago

PHP version history (2 changes)1.0.0PHP ^7.4

1.1.2PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f1c99f95f05f0fa52ddbc5f599729ad3c9f7273e6678d622de4c79c12cb9b2f?d=identicon)[hughsaffar](/maintainers/hughsaffar)

---

Top Contributors

[![hughsaffar](https://avatars.githubusercontent.com/u/10440022?v=4)](https://github.com/hughsaffar "hughsaffar (35 commits)")[![imanghafoori1](https://avatars.githubusercontent.com/u/6961695?v=4)](https://github.com/imanghafoori1 "imanghafoori1 (1 commits)")

---

Tags

laravelprofilingtestingtestlaravelprofiler

###  Code Quality

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hughsaffar-laravel-test-trap/health.svg)

```
[![Health](https://phpackages.com/badges/hughsaffar-laravel-test-trap/health.svg)](https://phpackages.com/packages/hughsaffar-laravel-test-trap)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k42.5M40.5k](/packages/orchestra-testbench)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2248.4k](/packages/guanguans-laravel-soar)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[cerbero/octane-testbench

Set of utilities to test Laravel applications powered by Octane.

434.2k1](/packages/cerbero-octane-testbench)

PHPackages © 2026

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