-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBundleFunctionalTest.php
More file actions
102 lines (92 loc) · 3.31 KB
/
BundleFunctionalTest.php
File metadata and controls
102 lines (92 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
namespace Pixelshaped\FlatMapperBundle\Tests\Functional;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Pixelshaped\FlatMapperBundle\FlatMapper;
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)]
class BundleFunctionalTest extends TestCase
{
public function testServiceWiring(): void
{
$kernel = new PixelshapedFlatMapperTestingKernel('test', true);
$kernel->boot();
$container = $kernel->getContainer();
$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
{
public function registerBundles(): iterable
{
return [
new PixelshapedFlatMapperBundle(),
];
}
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 []; }
};
}
}