dzolnierz/phpunit-accelerator

该软件包已废弃且不再维护。未建议替代软件包。

PHPUnit加速器

dev-master 2020-08-13 14:35 UTC

This package is not auto-updated.

Last update: 2020-08-13 14:36:27 UTC


README

Build Status

受Kris Wallsmith关于更快的PHPUnit文章(http://kriswallsmith.net/post/18029585104/faster-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创建 - 查看我们的博客,了解更多关于这个以及其他开源项目的信息。