patricksamson/phpunit-flaky-fix
Composer 安装命令:
composer require --dev patricksamson/phpunit-flaky-fix
包简介
A PHPUnit extension to help reproduce flaky tests.
README 文档
README
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
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.
Installation
composer require --dev patricksamson/phpunit-flaky-fix
You'll then need to register the extension in your phpunit.xml file:
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
+ <extensions>
+ <bootstrap class="PatrickSamson\PHPUnitFlakyFix\FlakyFixExtension" />
+ </extensions>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>
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
The extension works by:
- Generating a new, completely random seed at the start of your test suite execution, and displaying it in the output
- Seeding PHP's random number generator (
mt_rand()) with this value, beforesetUp()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
- This extension only affects PHP's
mt_rand()function and related randomness functions - It is not compatible with
random_int()as it can't be seeded. - It has no effect on time-based functions (e.g.,
time(),date(), ...), but that can be remediated using something likeCarbon::setTestNow($knownDate) - It does not control randomness from other sources (e.g., database auto-increment values, UUID generation, external API calls, ...)
- The seed is generated per test suite run, not per individual test
- Some PHPUnit features or third-party tools might interfere with the seed generation process or the output display
License
This project uses the MIT license.
Credits
The testing structure of this package is heavily inspired from ergebnis/phpunit-slow-test-detector, originally licensed under MIT by Andreas Möller.
patricksamson/phpunit-flaky-fix 适用场景与选型建议
patricksamson/phpunit-flaky-fix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 561 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「testing」 「phpunit」 「test」 「pest」 「flaky」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 patricksamson/phpunit-flaky-fix 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 patricksamson/phpunit-flaky-fix 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 patricksamson/phpunit-flaky-fix 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HiDev plugin for PHPUnit
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
The PHP SDK for Checkmango
PHPUnit DbUnit Native Array-based Fixtures
Alfabank REST API integration
统计信息
- 总下载量: 561
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-01