Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions tests/Functional/BundleFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand All @@ -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<string, mixed>|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<string, mixed> */
public function getMetadata(): array { return []; }
};
}
}