1515use Doctrine \ORM \Mapping \NamingStrategy ;
1616use Doctrine \ORM \Mapping \QuoteStrategy ;
1717use Doctrine \Persistence \Mapping \Driver \MappingDriver ;
18+ use DoctrineModule \Cache \LaminasStorageCache ;
1819use DoctrineORMModule \Options \Configuration ;
1920use DoctrineORMModule \Service \ConfigurationFactory ;
2021use DoctrineORMModuleTest \Assets \RepositoryClass ;
22+ use Laminas \Cache \Storage \Adapter \Memory ;
2123use Laminas \ServiceManager \Exception \InvalidArgumentException ;
2224use Laminas \ServiceManager \ServiceManager ;
2325use PHPUnit \Framework \TestCase ;
2729
2830use function assert ;
2931use function class_exists ;
32+ use function get_class ;
3033
3134class ConfigurationFactoryTest extends TestCase
3235{
@@ -37,13 +40,21 @@ public function setUp(): void
3740 {
3841 $ this ->serviceManager = new ServiceManager ();
3942 $ this ->factory = new ConfigurationFactory ('test_default ' );
40- $ this ->serviceManager ->setService ('doctrine.cache.array ' , new ArrayCache ());
43+ $ this ->serviceManager ->setService ('doctrine.cache.array ' , $ this -> getArrayCacheInstance ());
4144 $ this ->serviceManager ->setService (
4245 'doctrine.driver.orm_default ' ,
4346 $ this ->createMock (MappingDriver::class)
4447 );
4548 }
4649
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+
4758 public function testWillInstantiateConfigWithoutNamingStrategySetting (): void
4859 {
4960 $ config = [
@@ -164,7 +175,7 @@ public function testWillInstantiateConfigWithHydrationCacheSetting(): void
164175 $ this ->serviceManager ->setService ('config ' , $ config );
165176 $ factory = new ConfigurationFactory ('test_default ' );
166177 $ ormConfig = $ factory ($ this ->serviceManager , Configuration::class);
167- $ this ->assertInstanceOf (ArrayCache::class , $ ormConfig ->getHydrationCacheImpl ());
178+ $ this ->assertInstanceOf (get_class ( $ this -> getArrayCacheInstance ()) , $ ormConfig ->getHydrationCacheImpl ());
168179 }
169180
170181 public function testCanSetDefaultRepositoryClass (): void
@@ -184,7 +195,7 @@ public function testCanSetDefaultRepositoryClass(): void
184195
185196 $ factory = new ConfigurationFactory ('test_default ' );
186197 $ ormConfig = $ factory ($ this ->serviceManager , Configuration::class);
187- $ this ->assertInstanceOf (ArrayCache::class , $ ormConfig ->getHydrationCacheImpl ());
198+ $ this ->assertInstanceOf (get_class ( $ this -> getArrayCacheInstance ()) , $ ormConfig ->getHydrationCacheImpl ());
188199 }
189200
190201 public function testAcceptsMetadataFactory (): void
@@ -376,7 +387,7 @@ public function testCanInstantiateWithSecondLevelCacheConfig(): void
376387 $ reflProperty ->setAccessible (true );
377388 $ cacheDecorator = $ reflProperty ->getValue ($ cacheFactory );
378389 $ this ->assertInstanceOf (CacheAdapter::class, $ cacheDecorator );
379- $ this ->assertInstanceOf (ArrayCache::class , $ cacheDecorator ->getCache ());
390+ $ this ->assertInstanceOf (get_class ( $ this -> getArrayCacheInstance ()) , $ cacheDecorator ->getCache ());
380391 }
381392
382393 public function testConfigureMiddlewares (): void
0 commit comments