phphd/cache-test-bundle

Clearing Symfony cache pools between test runs

1.0.0 2023-12-30 15:53 UTC

This package is auto-updated.

Last update: 2024-03-30 00:18:03 UTC


README

🧰 Provides Symfony Cache clearing extension for PHPUnit.

Codecov Licence Build Status

Installation ⚒️

  1. Install via composer

    composer require --dev phphd/cache-test-bundle
  2. Enable the bundle in the bundles.php

    PhPhD\CacheTestBundle\PhdCacheTestBundle::class => ['test' => true],
  3. Add PHPUnit extension

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

Usage 🚀

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.