diff --git a/tests/Functional/BundleFunctionalTest.php b/tests/Functional/BundleFunctionalTest.php index f9cd187..fe01c2e 100644 --- a/tests/Functional/BundleFunctionalTest.php +++ b/tests/Functional/BundleFunctionalTest.php @@ -9,6 +9,8 @@ use Pixelshaped\FlatMapperBundle\PixelshapedFlatMapperBundle; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Contracts\Cache\CacheInterface; +use Symfony\Contracts\Cache\ItemInterface; #[CoversClass(FlatMapper::class)] #[CoversClass(PixelshapedFlatMapperBundle::class)] @@ -22,6 +24,15 @@ public function testServiceWiring(): void $flatMapper = $container->get('pixelshaped_flat_mapper.flat_mapper'); $this->assertInstanceOf(FlatMapper::class, $flatMapper); } + + public function testServiceWiringWithCacheService(): void + { + $kernel = new PixelshapedFlatMapperTestingKernelWithCache('test', true); + $kernel->boot(); + $container = $kernel->getContainer(); + $flatMapper = $container->get('pixelshaped_flat_mapper.flat_mapper'); + $this->assertInstanceOf(FlatMapper::class, $flatMapper); + } } class PixelshapedFlatMapperTestingKernel extends Kernel @@ -35,4 +46,57 @@ public function registerBundles(): iterable public function registerContainerConfiguration(LoaderInterface $loader) { } +} + +class PixelshapedFlatMapperTestingKernelWithCache extends Kernel +{ + public function registerBundles(): iterable + { + return [ + new PixelshapedFlatMapperBundle(), + ]; + } + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(function ($container) { + // Register a mock cache service + $container->register('cache.app', MockCacheAdapter::class); + + $container->loadFromExtension('pixelshaped_flat_mapper', [ + 'cache_service' => 'cache.app', + 'validate_mapping' => false, + ]); + }); + } +} + +class MockCacheAdapter implements CacheInterface +{ + /** + * @param array|null $metadata + */ + public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed + { + return $callback($this->createMockItem(), false); + } + + public function delete(string $key): bool + { + return true; + } + + private function createMockItem(): ItemInterface + { + return new class implements ItemInterface { + public function getKey(): string { return 'test'; } + public function get(): mixed { return null; } + public function isHit(): bool { return false; } + public function set(mixed $value): static { return $this; } + public function expiresAt(?\DateTimeInterface $expiration): static { return $this; } + public function expiresAfter(int|\DateInterval|null $time): static { return $this; } + public function tag(iterable|string $tags): static { return $this; } + /** @return array */ + public function getMetadata(): array { return []; } + }; + } } \ No newline at end of file