phphd / cache-test-bundle
Clearing Symfony cache pools between test runs
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
🧰 Provides Symfony Cache clearing extension for PHPUnit.
Installation ⚒️
-
Install via composer
composer require --dev phphd/cache-test-bundle
-
Enable the bundle in the
bundles.php
PhPhD\CacheTestBundle\PhdCacheTestBundle::class => ['test' => true],
-
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
.