mybuilder/phpunit-accelerator

PHPUnit加速器

2.0.0 2017-06-21 07:43 UTC

This package is auto-updated.

Last update: 2024-09-06 01:07:07 UTC


README

Build Status

受Kris Wallsmith关于更快的PHPUnit文章启发,我们创建了一个PHPUnit测试监听器,通过释放内存,将PHPUnit测试速度提高了约20%。

安装

要安装这个库,运行以下命令,您将获得最新版本

composer require mybuilder/phpunit-accelerator --dev

用法

只需将其添加到您的phpunit.xml配置中

<phpunit>
    <listeners>
        <listener class="\MyBuilder\PhpunitAccelerator\TestListener"/>
    </listeners>
</phpunit>

忽略测试

有时需要忽略特定的测试,因为这些测试的属性释放是不希望的。为此,您可以通过实现IgnoreTestPolicy接口来扩展监听器的行为。

例如,如果我们假设想要忽略所有测试文件名中包含"Legacy"的测试,我们可以创建一个自定义的忽略策略,如下所示

<?php

use MyBuilder\PhpunitAccelerator\IgnoreTestPolicy;

class IgnoreLegacyTestPolicy implements IgnoreTestPolicy {
    public function shouldIgnore(\ReflectionObject $testReflection) {
        return strpos($testReflection->getFilename(), 'Legacy') !== false;
    }
}

并将其传递到phpunit.xml配置中的测试监听器构造函数

<phpunit>
    <listeners>
        <listener class="\MyBuilder\PhpunitAccelerator\TestListener">
            <arguments>
                <object class="\IgnoreLegacyTestPolicy"/>
            </arguments>
        </listener>
    </listeners>
</phpunit>

MyBuilder创建 - 查看我们的博客以了解更多关于此以及其他我们发布的开源项目的信息。