🧰 Provides Symfony Cache clearing extension for PHPUnit.
-
Install via composer
composer require --dev phphd/cache-test-bundle
-
Enable the bundle in the
bundles.phpPhPhD\CacheTestBundle\PhdCacheTestBundle::class => ['test' => true],
-
Add PHPUnit extension
<extensions> <extension class="PhPhD\CacheTest\Hook\ClearCachePoolsExtension"/> </extensions>
It is possible to use this bundle to clear cache pools for any tests that extend
Symfony\Bundle\FrameworkBundle\Test\KernelTestCase (WebTestCase, ApiTestCase, etc.)
Use #[ClearPool] attribute in order to clear caches:
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();
}
}In the example above, my_cache_pool will be cleared before every test from BlogControllerTest.