phphd / cache-test-bundle
在测试运行之间清除 Symfony 缓存池
1.0.0
2023-12-30 15:53 UTC
Requires
- php: >=8.0.2
- phpunit/phpunit: ^9.4
- psr/cache: ^2.0|^3.0
- symfony/dependency-injection: ^6.0
- symfony/http-kernel: ^6.0
Requires (Dev)
- phphd/coding-standard: 0.4.*
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.3
- psalm/plugin-phpunit: ^0.18.4
- symfony/var-dumper: ^6.0
- symplify/easy-coding-standard: ^12.0
- vimeo/psalm: ^5.15
README
🧰 提供用于 PHPUnit 的 Symfony 缓存清除扩展。
安装 ⚒️
-
使用 composer 安装
composer require --dev phphd/cache-test-bundle
-
在
bundles.php
中启用该捆绑包PhPhD\CacheTestBundle\PhdCacheTestBundle::class => ['test' => true],
-
添加 PHPUnit 扩展
<extensions> <extension class="PhPhD\CacheTest\Hook\ClearCachePoolsExtension"/> </extensions>
使用 🚀
可以使用此捆绑包清除任何扩展 Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
(WebTestCase
,ApiTestCase
等)的测试的缓存池
使用 #[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
运行的测试之前被清除。