66use Doctrine \Bundle \DoctrineBundle \Tests \TestCase ;
77use Doctrine \Common \Cache \Psr6 \DoctrineProvider ;
88use Doctrine \Deprecations \PHPUnit \VerifyDeprecations ;
9+ use Doctrine \ORM \Cache \CacheEntry ;
10+ use Doctrine \ORM \Cache \CacheKey ;
11+ use Doctrine \ORM \Cache \CollectionCacheEntry ;
12+ use Doctrine \ORM \Cache \Lock ;
913use Doctrine \ORM \Cache \Region ;
1014use Doctrine \ORM \EntityManagerInterface ;
1115use PHPUnit \Framework \Attributes \DoesNotPerformAssertions ;
1216use PHPUnit \Framework \Attributes \IgnoreDeprecations ;
17+ use RuntimeException ;
1318use Symfony \Component \Cache \Adapter \ArrayAdapter ;
1419use Symfony \Component \Config \Loader \LoaderInterface ;
1520use Symfony \Component \DependencyInjection \ContainerBuilder ;
1621use Symfony \Component \DependencyInjection \Definition ;
1722
18- use function get_class ;
1923use function interface_exists ;
2024
2125class CacheCompatibilityPassTest extends TestCase
@@ -33,18 +37,11 @@ public static function setUpBeforeClass(): void
3337
3438 public function testCacheConfigUsingServiceDefinedByApplication (): void
3539 {
36- $ customRegionClass = get_class ($ this ->createMock (Region::class));
37-
38- (new class ($ customRegionClass ) extends TestKernel {
39- public function __construct (private readonly string $ regionClass )
40- {
41- parent ::__construct (false );
42- }
43-
40+ (new class (false ) extends TestKernel {
4441 public function registerContainerConfiguration (LoaderInterface $ loader ): void
4542 {
4643 parent ::registerContainerConfiguration ($ loader );
47- $ loader ->load (function (ContainerBuilder $ containerBuilder ): void {
44+ $ loader ->load (static function (ContainerBuilder $ containerBuilder ): void {
4845 $ containerBuilder ->loadFromExtension ('framework ' , [
4946 'cache ' => [
5047 'pools ' => [
@@ -64,13 +61,16 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
6461 'regions ' => [
6562 'filelock ' => ['type ' => 'filelock ' , 'lifetime ' => 0 , 'cache_driver ' => ['type ' => 'pool ' , 'pool ' => 'doctrine.system_cache_pool ' ]],
6663 'lifelong ' => ['lifetime ' => 0 , 'cache_driver ' => ['type ' => 'pool ' , 'pool ' => 'doctrine.system_cache_pool ' ]],
67- 'entity_cache_region ' => ['type ' => 'service ' , 'service ' => $ this ->regionClass ],
64+ 'entity_cache_region ' => [
65+ 'type ' => 'service ' ,
66+ 'service ' => TestRegion::class,
67+ ],
6868 ],
6969 ],
7070 ],
7171 ],
7272 );
73- $ containerBuilder ->register ($ this -> regionClass , $ this -> regionClass );
73+ $ containerBuilder ->register (TestRegion::class, TestRegion::class );
7474 $ containerBuilder ->setDefinition (
7575 'custom_cache_service ' ,
7676 new Definition (ArrayAdapter::class),
@@ -132,3 +132,45 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
132132 })->boot ();
133133 }
134134}
135+
136+ if (! interface_exists (Region::class)) {
137+ return ;
138+ }
139+
140+ final class TestRegion implements Region
141+ {
142+ public function getName (): string
143+ {
144+ return 'test_region ' ;
145+ }
146+
147+ public function contains (CacheKey $ key ): bool
148+ {
149+ throw new RuntimeException ('Not implemented ' );
150+ }
151+
152+ public function get (CacheKey $ key ): CacheEntry |null
153+ {
154+ throw new RuntimeException ('Not implemented ' );
155+ }
156+
157+ public function getMultiple (CollectionCacheEntry $ collection ): array |null
158+ {
159+ throw new RuntimeException ('Not implemented ' );
160+ }
161+
162+ public function put (CacheKey $ key , CacheEntry $ entry , Lock |null $ lock = null ): bool
163+ {
164+ throw new RuntimeException ('Not implemented ' );
165+ }
166+
167+ public function evict (CacheKey $ key ): bool
168+ {
169+ throw new RuntimeException ('Not implemented ' );
170+ }
171+
172+ public function evictAll (): bool
173+ {
174+ throw new RuntimeException ('Not implemented ' );
175+ }
176+ }
0 commit comments