PHPackages                             patricksamson/phpunit-flaky-fix - 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. patricksamson/phpunit-flaky-fix

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

patricksamson/phpunit-flaky-fix
===============================

A PHPUnit extension to help reproduce flaky tests.

1.3.0(5mo ago)1561↓50%MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI failing

Since Aug 4Pushed 5mo agoCompare

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

READMEChangelog (5)Dependencies (7)Versions (15)Used By (0)

PHPUnit Flaky Fix
=================

[](#phpunit-flaky-fix)

[![Tests](https://github.com/patricksamson/phpunit-flaky-fix/workflows/Tests/badge.svg)](https://github.com/patricksamson/phpunit-flaky-fix/actions)

[![Latest Stable Version](https://camo.githubusercontent.com/9cbdb2d1ef2e22864273625e0586a2262b3489e16582aa2239bf3b0c2a102521/68747470733a2f2f706f7365722e707567782e6f72672f7061747269636b73616d736f6e2f706870756e69742d666c616b792d6669782f762f737461626c65)](https://packagist.org/packages/patricksamson/phpunit-flaky-fix)[![Total Downloads](https://camo.githubusercontent.com/7462f2c4c6dd8c542f6d0d072287c94cb850b92091896921bff19729f7ede805/68747470733a2f2f706f7365722e707567782e6f72672f7061747269636b73616d736f6e2f706870756e69742d666c616b792d6669782f646f776e6c6f616473)](https://packagist.org/packages/patricksamson/phpunit-flaky-fix)[![Monthly Downloads](https://camo.githubusercontent.com/da8b75afafbdeba3dd52ab26c5761d3e5b431d8a026a41e20a2b9b2c5e8b633b/687474703a2f2f706f7365722e707567782e6f72672f7061747269636b73616d736f6e2f706870756e69742d666c616b792d6669782f642f6d6f6e74686c79)](https://packagist.org/packages/patricksamson/phpunit-flaky-fix)

This package provides a PHPUnit extension that helps reproduce flaky tests by seeding the random number generator with a consistent value across test runs. This allows you to reproduce and debug flaky tests more easily.

Compatibility
-------------

[](#compatibility)

This package is compatible with the following versions of PHP and PHPUnit:

- **PHP :** `^8.1 || ^8.2 || ^8.3 || ^8.4 || ^8.5`
- **PHPUnit :** `^10.0 || ^11.0 || ^12.0`

It has been tested with the following versions of popular tools that wrap PHPUnit:

- **Paratest :** `^7.0`
- **Pest :** `^2.0 || ^3.0 || ^4.0` (this package includes a Pest Plugin for improved compatibility)

It is compatible with any tool that uses `mt_rand()` for randomness in tests, such as [Faker](https://github.com/FakerPHP/Faker).

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

[](#installation)

```
composer require --dev patricksamson/phpunit-flaky-fix
```

You'll then need to register the extension in your `phpunit.xml` file:

```

+
+
+

             tests/Unit/

```

Usage
-----

[](#usage)

When you have bootstrapped the extension, you can run your tests as usual:

```
vendor/bin/phpunit
php artisan test
php artisan test --parallel
```

The generated `Flaky Test Seed` will be one of the first lines in the output, and you can use it to reproduce flaky test failures.

```
vendor/bin/phpunit --colors=always

Flaky Test Seed: 2031556362. To reproduce, run `FLAKY_SEED=2031556362 php artisan test --filter ...`

PHPUnit 12.3.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.10
Configuration: /home/runner/work/phpunit-flaky-fix/phpunit-flaky-fix/phpunit.xml

...........                                                       11 / 11 (100%)

Time: 00:00.003, Memory: 14.00 MB

OK (11 tests, 35 assertions)
```

How It Works
------------

[](#how-it-works)

The extension works by:

1. Generating a new, completely random seed at the start of your test suite execution, and displaying it in the output
2. Seeding PHP's random number generator (`mt_rand()`) with this value, before `setUp()` is called for each test

This ensures that your tests remain deterministic and reproducible, while still allowing for randomness between different test suite runs. To reproduce a flaky test failure, simply re-run that specific test with the provided seed.

In practice, there is some additional complexity to ensure compatibility with parallel test execution and other PHPUnit features.

Limitations
-----------

[](#limitations)

1. This extension only affects PHP's `mt_rand()` function and related randomness functions
2. It is not compatible with [`random_int()`](https://www.php.net/manual/en/function.random-int.php) as it can't be seeded.
3. It has no effect on time-based functions (e.g., `time()`, `date()`, ...), but that can be remediated using something like `Carbon::setTestNow($knownDate)`
4. It does not control randomness from other sources (e.g., database auto-increment values, UUID generation, external API calls, ...)
5. The seed is generated per test suite run, not per individual test
6. Some PHPUnit features or third-party tools might interfere with the seed generation process or the output display

License
-------

[](#license)

This project uses the [MIT license](LICENSE.md).

Credits
-------

[](#credits)

The testing structure of this package is heavily inspired from [`ergebnis/phpunit-slow-test-detector`](https://github.com/ergebnis/phpunit-slow-test-detector), originally licensed under MIT by [Andreas Möller](https://github.com/ergebnis).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance72

Regular maintenance activity

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~31 days

Total

5

Last Release

156d ago

PHP version history (2 changes)1.0.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

1.3.0PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/00961241bfba1f54c7c590fad6b3f8ece27d3783727f6371f69b9cd560df93ab?d=identicon)[Lykegenes](/maintainers/Lykegenes)

---

Top Contributors

[![patricksamson](https://avatars.githubusercontent.com/u/1416027?v=4)](https://github.com/patricksamson "patricksamson (73 commits)")

---

Tags

phptestingphpunittestpestflakyreproduce

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/patricksamson-phpunit-flaky-fix/health.svg)

```
[![Health](https://phpackages.com/badges/patricksamson-phpunit-flaky-fix/health.svg)](https://phpackages.com/packages/patricksamson-phpunit-flaky-fix)
```

###  Alternatives

[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)[juampi92/test-seo

Easy way to test your SEO

26341.0k](/packages/juampi92-test-seo)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

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