15
15
use Doctrine \ORM \Mapping \NamingStrategy ;
16
16
use Doctrine \ORM \Mapping \QuoteStrategy ;
17
17
use Doctrine \Persistence \Mapping \Driver \MappingDriver ;
18
+ use DoctrineModule \Cache \LaminasStorageCache ;
18
19
use DoctrineORMModule \Options \Configuration ;
19
20
use DoctrineORMModule \Service \ConfigurationFactory ;
20
21
use DoctrineORMModuleTest \Assets \RepositoryClass ;
22
+ use Laminas \Cache \Storage \Adapter \Memory ;
21
23
use Laminas \ServiceManager \Exception \InvalidArgumentException ;
22
24
use Laminas \ServiceManager \ServiceManager ;
23
25
use PHPUnit \Framework \TestCase ;
27
29
28
30
use function assert ;
29
31
use function class_exists ;
32
+ use function get_class ;
30
33
31
34
class ConfigurationFactoryTest extends TestCase
32
35
{
@@ -37,13 +40,21 @@ public function setUp(): void
37
40
{
38
41
$ this ->serviceManager = new ServiceManager ();
39
42
$ this ->factory = new ConfigurationFactory ('test_default ' );
40
- $ this ->serviceManager ->setService ('doctrine.cache.array ' , new ArrayCache ());
43
+ $ this ->serviceManager ->setService ('doctrine.cache.array ' , $ this -> getArrayCacheInstance ());
41
44
$ this ->serviceManager ->setService (
42
45
'doctrine.driver.orm_default ' ,
43
46
$ this ->createMock (MappingDriver::class)
44
47
);
45
48
}
46
49
50
+ protected function getArrayCacheInstance (): object
51
+ {
52
+ // Set up appropriate cache based on DoctrineModule version detection:
53
+ return class_exists (ArrayCache::class)
54
+ ? new ArrayCache () // DoctrineModule 5
55
+ : new LaminasStorageCache (new Memory ()); // DoctrineModule 6
56
+ }
57
+
47
58
public function testWillInstantiateConfigWithoutNamingStrategySetting (): void
48
59
{
49
60
$ config = [
@@ -164,7 +175,7 @@ public function testWillInstantiateConfigWithHydrationCacheSetting(): void
164
175
$ this ->serviceManager ->setService ('config ' , $ config );
165
176
$ factory = new ConfigurationFactory ('test_default ' );
166
177
$ ormConfig = $ factory ($ this ->serviceManager , Configuration::class);
167
- $ this ->assertInstanceOf (ArrayCache::class , $ ormConfig ->getHydrationCacheImpl ());
178
+ $ this ->assertInstanceOf (get_class ( $ this -> getArrayCacheInstance ()) , $ ormConfig ->getHydrationCacheImpl ());
168
179
}
169
180
170
181
public function testCanSetDefaultRepositoryClass (): void
@@ -184,7 +195,7 @@ public function testCanSetDefaultRepositoryClass(): void
184
195
185
196
$ factory = new ConfigurationFactory ('test_default ' );
186
197
$ ormConfig = $ factory ($ this ->serviceManager , Configuration::class);
187
- $ this ->assertInstanceOf (ArrayCache::class , $ ormConfig ->getHydrationCacheImpl ());
198
+ $ this ->assertInstanceOf (get_class ( $ this -> getArrayCacheInstance ()) , $ ormConfig ->getHydrationCacheImpl ());
188
199
}
189
200
190
201
public function testAcceptsMetadataFactory (): void
@@ -376,7 +387,7 @@ public function testCanInstantiateWithSecondLevelCacheConfig(): void
376
387
$ reflProperty ->setAccessible (true );
377
388
$ cacheDecorator = $ reflProperty ->getValue ($ cacheFactory );
378
389
$ this ->assertInstanceOf (CacheAdapter::class, $ cacheDecorator );
379
- $ this ->assertInstanceOf (ArrayCache::class , $ cacheDecorator ->getCache ());
390
+ $ this ->assertInstanceOf (get_class ( $ this -> getArrayCacheInstance ()) , $ cacheDecorator ->getCache ());
380
391
}
381
392
382
393
public function testConfigureMiddlewares (): void
0 commit comments