88use Doctrine \DBAL \Configuration ;
99use Doctrine \DBAL \Connection ;
1010use Doctrine \DBAL \Driver \Middleware ;
11+ use RunOpenCode \Bundle \QueryResourcesLoader \Cache \CacheMiddleware ;
12+ use RunOpenCode \Bundle \QueryResourcesLoader \Tests \Fixtures \Fixtures ;
1113use RunOpenCode \Bundle \QueryResourcesLoader \Tests \Resources \App \TestKernel ;
1214use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase as SymfonyKernelTestCase ;
15+ use Symfony \Contracts \Cache \CacheInterface ;
16+ use Symfony \Contracts \Cache \TagAwareCacheInterface ;
1317
1418/**
1519 * @psalm-suppress UnnecessaryVarAnnotation, PossiblyNullFunctionCall, UndefinedThisPropertyFetch
1620 */
1721abstract class KernelTestCase extends SymfonyKernelTestCase
1822{
23+ protected function setUp (): void
24+ {
25+ parent ::setUp ();
26+ $ this ->clearCache ();
27+ }
28+
1929 protected static function getKernelClass (): string
2030 {
2131 return TestKernel::class;
2232 }
33+
34+ protected final function createFixtures (): void
35+ {
36+ $ this ->getContainer ()->get (Fixtures::class)->execute (); // @phpstan-ignore-line
37+ $ this ->clearLoggedQueryStatements ();
38+ }
2339
24- protected function clearLoggedQueryStatements (): void
40+ protected final function clearLoggedQueryStatements (): void
2541 {
2642 /** @var Configuration $configuration */
2743 $ configuration = $ this ->getContainer ()->get (Connection::class)->getConfiguration (); // @phpstan-ignore-line
@@ -37,7 +53,7 @@ protected function clearLoggedQueryStatements(): void
3753 /**
3854 * @return array<string, string[]>
3955 */
40- protected function getLoggedQueryStatements (): array
56+ protected final function getLoggedQueryStatements (): array
4157 {
4258 /** @var Configuration $configuration */
4359 $ configuration = $ this ->getContainer ()->get (Connection::class)->getConfiguration (); // @phpstan-ignore-line
@@ -60,4 +76,27 @@ protected function getLoggedQueryStatements(): array
6076
6177 return $ result ;
6278 }
79+
80+ /**
81+ * Clear cache for the current test.
82+ */
83+ protected final function clearCache (): void
84+ {
85+ $ booted = self ::$ booted ;
86+
87+ if (!$ booted ) {
88+ self ::bootKernel ();
89+ }
90+
91+ /** @var CacheInterface&TagAwareCacheInterface $pool */
92+ $ pool = $ this ->getContainer ()->get ('app.roc_test_cache ' );
93+
94+ $ pool ->invalidateTags ([
95+ CacheMiddleware::TAG ,
96+ ]);
97+
98+ if ($ booted ) {
99+ self ::ensureKernelShutdown ();
100+ }
101+ }
63102}
0 commit comments