定制 alorel/phpunit-auto-rerun 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alorel/phpunit-auto-rerun

最新稳定版本:0.2

Composer 安装命令:

composer require alorel/phpunit-auto-rerun

包简介

Allows failed PHPUnit tests to automatically rerun.

README 文档

README

Average time to resolve an issue Percentage of issues still open Build Status codecov Dependency Status Reference Status HHVM Status

Latest Stable Version Total Downloads License

Allows failed PHPUnit tests to automatically rerun.

Use cases

Anywhere where there is an external dependency which you don't have full control of, e.g. when developing an SDK for some API, which might apply rate limiting or experience brief downtime.

Requirements

  • Tested on HHVM
  • PHP 5.6 or 7.0+
  • Tested on PHPUnit 5.4 (require-dev ^5.0), but might run on older versions (update your installation!)

Installation

composer require --dev alorel/phpunit-auto-rerun

Usage

You can integrate retry functionality in your tests in one of two ways: using class inheritance or using traits.

In many situations, you can simply extend your test cases from PHPUnit_Retriable_TestCase, which itself extends the original PHPUnit_Framework_TestCase. Here, all you need to do is replace the class in your test cases:

<?php

    namespace Some\Thing\Or\Another;

    class PHPUnitReflectionTest extends \PHPUnit_Framework_TestCase {

would become

<?php

    namespace Some\Thing\Or\Another;

    class PHPUnitReflectionTest extends \PHPUnit_Retriable_TestCase {

In situations where your test cases have complex inheritance already, you can just use a trait in the test cases that need retry functionality:

<?php

    namespace Some\Thing\Or\Another;

    class MyTestCase extends MyTestBase {

        use \PHPUnit_Retriable_TestCase_Trait;

    }

Modifying existing test cases/reverting back

The PHPUnit_Retriable_TestCase class was intentionally left in the global namespace to resemble the original PHPUnit_Framework_TestCase as much as possible. Most IDEs will generate/suggest a test case template to contain

class PHPUnitReflectionTest extends \PHPUnit_Retriable_TestCase

so you can safely do a tests-wide search-and-replace operation in either direction.

Configuration

Configuration is performed via annotations, same way you'd configure expected exceptions, @befores and so on:

  • @retryCount specifies the maximum number of times a test case will run. Setting this to 0 will simply invoke the original test runner, setting it to 1 will run a test without retries (equivalent functionality), setting it to 5 will run it once and retry up to 4 times upon failure.
  • @sleepTime specifies how many seconds the script will sleep between retries.

Both these values default to 0.

Configuration can be performed by annotating both the class and the test method - class annotations are applied to all methods and are overriden by method annotations, for example, consider the following snippet:

<?php

    /**
     * @retryCount 5
     */
    class SomeTest extends PHPUnit_Retriable_TestCase {

        function testOne() {
            //Will inherit the default sleep time of 0
            //and SomeTest's retry count of 5
        }

        /**
         * @retryCount 0
         */
        function testTwo() {
            //sleep time 0 (default)
            //retry count 0 (overrides SomeTest)
        }

        /**
         * @sleepTime 10
         */
        function testThree() {
            //sleep time 10 (overrides default)
            //retry count 5 (inherit from SomeTest)
        }

        /**
         * @sleepTime 3
         * @retryCount 3
         */
        function testFour() {
            //sleep time 3 (overrides default)
            //retry count 3 (overrides SomeTest)
        }
    }

FAQ *

Q: Will this work with @dataProvider annotations? A: Yes - the test will continue retrying with the same data provider value and continue to the next one when the test succeeds. This applies to both array data providers and generators/iterators.

Q: Why do I end up with a higher number of assertions than before? A: Even when a test fails it still increments the number of assertions made - it was not immediately obvious how to change this and I don't see it as an important feature, therefore I didn't bother implementing it.

Q: Can I set the configuration parameters via CLI/phpunit.xml? A: No and it does not appear to be possible without editing the original PHPUnit code.

* I wrote put these together before release, no one's asked them. Apologies for the ruse. 😞

alorel/phpunit-auto-rerun 适用场景与选型建议

alorel/phpunit-auto-rerun 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.19k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「phpunit」 「test」 「retry」 「auto」 「failed」 「rerun」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alorel/phpunit-auto-rerun 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alorel/phpunit-auto-rerun 我们能提供哪些服务?
定制开发 / 二次开发

基于 alorel/phpunit-auto-rerun 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.19k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 15
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1
  • 更新时间: 2016-06-20