@@ -615,6 +615,14 @@ public function testPropertyInfoEnabled()
615615 $ this ->assertTrue ($ container ->has ('property_info ' ));
616616 }
617617
618+ public function testCacheAdapterServices ()
619+ {
620+ $ container = $ this ->createContainerFromFile ('cache ' );
621+
622+ $ this ->assertCacheAdaptersServiceDefinitionIsCreated ($ container , 'foo ' , 'cache.adapter.foo ' , null , 30 );
623+ $ this ->assertCacheAdaptersServiceDefinitionIsCreated ($ container , 'app_redis ' , 'cache.adapter.redis ' , 'app.redis_connection ' , 30 );
624+ }
625+
618626 public function testCachePoolServices ()
619627 {
620628 $ container = $ this ->createContainerFromFile ('cache ' );
@@ -697,6 +705,46 @@ private function assertVersionStrategy(ContainerBuilder $container, Reference $r
697705 }
698706 }
699707
708+ private function assertCacheAdaptersServiceDefinitionIsCreated (ContainerBuilder $ container , $ name , $ parent , $ provider , $ defaultLifetime )
709+ {
710+ $ id = 'cache.adapter. ' .$ name ;
711+
712+ $ this ->assertTrue ($ container ->has ($ id ), sprintf ('Service definition "%s" for cache adapter "%s" is registered ' , $ id , $ name ));
713+
714+ $ adapterDefinition = $ container ->getDefinition ($ id );
715+
716+ $ this ->assertTrue ($ adapterDefinition ->hasTag ('cache.pool ' ), sprintf ('Service definition "%s" is tagged with the "cache.pool" tag. ' , $ id ));
717+ $ this ->assertTrue ($ adapterDefinition ->isAbstract (), sprintf ('Service definition "%s" is abstract. ' , $ id ));
718+
719+ $ tag = $ adapterDefinition ->getTag ('cache.pool ' );
720+ $ this ->assertTrue (isset ($ tag [0 ]['default_lifetime ' ]), 'The default lifetime is stored as an attribute of the "cache.pool" tag. ' );
721+ $ this ->assertSame ($ defaultLifetime , $ tag [0 ]['default_lifetime ' ], 'The default lifetime is stored as an attribute of the "cache.pool" tag. ' );
722+
723+ if ($ provider ) {
724+ $ this ->assertTrue (isset ($ tag [0 ]['provider ' ]), 'The provider is stored as an attribute of the "cache.pool" tag. ' );
725+ $ this ->assertSame ($ provider , $ tag [0 ]['provider ' ], 'The provider is stored as an attribute of the "cache.pool" tag. ' );
726+ } else {
727+ $ this ->assertFalse (isset ($ tag [0 ]['provider ' ]), 'No provider is stored as an attribute of the "cache.pool" tag. ' );
728+ }
729+
730+ $ this ->assertInstanceOf (DefinitionDecorator::class, $ adapterDefinition , sprintf ('Cache adapter "%s" is based on a parent. ' , $ name ));
731+
732+ $ adapterId = $ adapterDefinition ->getParent ();
733+ $ adapterDefinition = $ container ->findDefinition ($ adapterId );
734+
735+ switch ($ parent ) {
736+ case 'cache.adapter.apcu ' :
737+ $ this ->assertSame (ApcuAdapter::class, $ adapterDefinition ->getClass ());
738+ break ;
739+ case 'cache.adapter.doctrine ' :
740+ $ this ->assertSame (DoctrineAdapter::class, $ adapterDefinition ->getClass ());
741+ break ;
742+ case 'cache.adapter.filesystem ' :
743+ $ this ->assertSame (FilesystemAdapter::class, $ adapterDefinition ->getClass ());
744+ break ;
745+ }
746+ }
747+
700748 private function assertCachePoolServiceDefinitionIsCreated (ContainerBuilder $ container , $ name , $ adapter , $ defaultLifetime )
701749 {
702750 $ id = 'cache.pool. ' .$ name ;
@@ -728,7 +776,5 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
728776 $ this ->assertSame (FilesystemAdapter::class, $ adapterDefinition ->getClass ());
729777 break ;
730778 }
731-
732- $ this ->assertTrue ($ adapterDefinition ->isAbstract (), sprintf ('Service definition "%s" is abstract. ' , $ adapterId ));
733779 }
734780}
0 commit comments