petrkotek/phpunit-naughtytestdetector
Composer 安装命令:
composer require petrkotek/phpunit-naughtytestdetector
包简介
"Naughty test detector" for PHPUnit. Identifies tests, which don't clean after themselves.
README 文档
README
"Naughty test detector" for PHPUnit. Identifies tests leaving garbage after themselves.
Many of us have been there - your integration test works in isolation, but breaks when running in a sequence of tests.
This can be very difficult to troubleshoot, but luckily phpunit-naughtytestdetector is here to help.
Requirements
- PHPUnit 6.0+
- Supported PHP versions: 7.0 and 7.1
Note: for older PHPUnit or PHP 5.6, use v0.2.0.
Installation
NaughtyTestDetector is installable via Composer and should be added as a require-dev dependency:
composer require --dev petrkotek/phpunit-naughtytestdetector
Usage
1. Enable NaughtyTestListener by adding the following to your test suite's phpunit.xml file:
<phpunit bootstrap="vendor/autoload.php"> ... <listeners> <listener class="PetrKotek\NaughtyTestDetector\PHPUnit\Listeners\NaughtyTestListener"> <arguments> <!-- Class name of your own MetricFetcher --> <string>MyProject\TestUtils\MyMetricFetcher</string> <!-- Optional constructor arguments for the metric fetcher --> <array> <element> <string>hello world</string> </element> </array> <!-- Optionally specify levels on which MetricFetcher should be executed --> <!-- Note: values below are the default ones --> <array> <element key="executeOnTestLevel"> <boolean>false</boolean> </element> <element key="executeOnTestSuiteLevel"> <boolean>true</boolean> </element> <element key="executeOnGlobalLevel"> <boolean>false</boolean> </element> </array> </arguments> </listener> </listeners> </phpunit>
2. Implement the MetricFetcher interface, e.g.:
namespace MyProject\TestUtils\MyMetricFetcher; use PetrKotek\NaughtyTestDetector\MetricFetcher; class MyMetricFetcher implements MetricFetcher { private $db; public function __construct() { $this->db = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db"); } /** * @return array */ public function fetchMetrics() { $result = mysqli_query($this->db, 'SELECT COUNT * FROM my_table'); $row = mysqli_fetch_row($result); return ['records' => $row[0]; } }
Tip: You can also use built-in metric fetcher, e.g. PetrKotek\NaughtyTestDetector\MetricFetchers\GlobalsMetricFetcher.
3. Run your test suite.
E.g. phpunit --configuration integration.xml
NaughtyTestListener will fetch metrics before & after each TestSuite (aka "test class") and if there is a difference
between before & after, it prints out like message like this:
MyProject\Integration\MyNamespace\BadTest is naughty!
- my_table: 0 -> 5 (+5)
This means, that before the test, there was 0 records in the my_table and after executing all the tests, there were
5 records.
Note: If you want to temporarily disable Naughty Test Detector, use DISABLE_NAUGHTY_TEST_DETECTOR enviromental variable, e.g. DISABLE_NAUGHTY_TEST_DETECTOR=1 phpunit --configuration integration.xml.
petrkotek/phpunit-naughtytestdetector 适用场景与选型建议
petrkotek/phpunit-naughtytestdetector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 791.79k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「phpunit」 「cleanup」 「detector」 「cleaning」 「messy」 「naughty」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 petrkotek/phpunit-naughtytestdetector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 petrkotek/phpunit-naughtytestdetector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 petrkotek/phpunit-naughtytestdetector 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HiDev plugin for PHPUnit
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
Shim repository for phpmd/phpmd
Library that let you catch fatal errors
Parses a user agent string to detect Internet Explorer
统计信息
- 总下载量: 791.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache
- 更新时间: 2016-10-13