phphd/cache-test-bundle

在测试运行之间清除 Symfony 缓存池

1.0.0 2023-12-30 15:53 UTC

This package is auto-updated.

Last update: 2024-08-30 01:29:12 UTC


README

🧰 提供用于 PHPUnit 的 Symfony 缓存清除扩展。

Codecov Licence Build Status

安装 ⚒️

  1. 使用 composer 安装

    composer require --dev phphd/cache-test-bundle
  2. bundles.php 中启用该捆绑包

    PhPhD\CacheTestBundle\PhdCacheTestBundle::class => ['test' => true],
  3. 添加 PHPUnit 扩展

        <extensions>
            <extension class="PhPhD\CacheTest\Hook\ClearCachePoolsExtension"/>
        </extensions>

使用 🚀

可以使用此捆绑包清除任何扩展 Symfony\Bundle\FrameworkBundle\Test\KernelTestCaseWebTestCaseApiTestCase 等)的测试的缓存池

使用 #[ClearPool] 属性来清除缓存

use PhPhD\CacheTest\ClearPool;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

#[ClearPool('my_cache_pool')]
final class BlogControllerTest extends WebTestCase
{
    public function testIndex(): void
    {
        $client = static::createClient();
        $client->request('GET', '/en/blog/');

        self::assertResponseIsSuccessful();
    }
}

在上面的示例中,my_cache_pool 将在每次从 BlogControllerTest 运行的测试之前被清除。