ruano_a/reload-annotation-bundle

一个提供 PHPUnit 扩展的 Symfony 包,当测试方法上存在注释时会重新加载数据库。

1.0.0 2020-08-25 04:52 UTC

This package is auto-updated.

Last update: 2024-09-08 06:26:29 UTC


README

https://github.com/ruano-a/selective-test-isolation-bundle 使用回滚,这更快更好。

ReloadAnnotationBundle

一个提供 PHPUnit 扩展的 Symfony 包,当测试方法上存在注释时会重新加载数据库。它仅适用于版本 >= 7.5 的 PHPUnit。

配置

composer require --dev ruano_a/reload-annotation-bundle

在 bundles.php 中添加该包

if (in_array($env, ['dev', 'test'])) {
    ...
    if ($env === 'test') {
        $bundles[] = new ruano_a\ReloadAnnotationBundle\ReloadAnnotationBundle();
    }
}

在您的 xml 配置(phpunit.xml)中添加扩展

    <phpunit>
        ...
        <extensions>
            <extension class="ruano_a\ReloadAnnotationBundle\PHPUnit\PHPUnitExtension" />
        </extensions>
    </phpunit>

就是这样。

可用注释

  • ReloadDatabaseBefore
  • ReloadDatabaseAfter

注意

此包无法与版本低于 7.5 的 PHPUnit 一起使用,因为监听器系统似乎不允许获取测试方法信息。目前不可配置,如果不想等待,请联系我。它是为我个人使用而制作的,但对于大多数常见情况,建议使用此包:https://github.com/dmaicher/doctrine-test-bundle,该包优化得更好,但无法选择何时执行回滚。