From 1046038fbe6ea8e35958117520d17d7feffbda42 Mon Sep 17 00:00:00 2001 From: Tomas Date: Fri, 20 Sep 2019 14:04:34 +0300 Subject: [PATCH] Allow cache lifetime as null --- .../BazingaGeocoderExtension.php | 4 ++- Tests/Functional/BundleInitializationTest.php | 25 +++++++++++++++++++ .../config/cache_without_lifetime.yml | 12 +++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Tests/Functional/config/cache_without_lifetime.yml diff --git a/DependencyInjection/BazingaGeocoderExtension.php b/DependencyInjection/BazingaGeocoderExtension.php index 0b4c0a35..f1f0d88d 100644 --- a/DependencyInjection/BazingaGeocoderExtension.php +++ b/DependencyInjection/BazingaGeocoderExtension.php @@ -112,6 +112,8 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con } if (isset($config['cache']) || isset($config['cache_lifetime']) || isset($config['cache_precision'])) { + $cacheLifetime = isset($config['cache_lifetime']) ? (int) $config['cache_lifetime'] : null; + if (null === $cacheServiceId = $config['cache']) { if (!$container->has('app.cache')) { throw new \LogicException('You need to specify a service for cache.'); @@ -121,7 +123,7 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con $plugins[] = $providerServiceId.'.cache'; $container->register($providerServiceId.'.cache', CachePlugin::class) ->setPublic(false) - ->setArguments([new Reference($cacheServiceId), (int) $config['cache_lifetime'], $config['cache_precision']]); + ->setArguments([new Reference($cacheServiceId), $cacheLifetime, $config['cache_precision']]); } if (isset($config['limit'])) { diff --git a/Tests/Functional/BundleInitializationTest.php b/Tests/Functional/BundleInitializationTest.php index 362bf9a2..58e578d3 100644 --- a/Tests/Functional/BundleInitializationTest.php +++ b/Tests/Functional/BundleInitializationTest.php @@ -89,6 +89,31 @@ public function testBundleWithCachedProvider() $this->assertInstanceOf(CachePlugin::class, $plugins[0]); } + public function testCacheLifetimeCanBeNull() + { + $kernel = $this->createKernel(); + $kernel->addConfigFile(__DIR__.'/config/cache_without_lifetime.yml'); + + $this->bootKernel(); + + $container = $this->getContainer(); + + self::assertTrue($container->has('bazinga_geocoder.provider.acme')); + + /** @var PluginProvider $service */ + $service = $container->get('bazinga_geocoder.provider.acme'); + self::assertInstanceOf(PluginProvider::class, $service); + + $plugins = NSA::getProperty($service, 'plugins'); + self::assertCount(1, $plugins); + + $cachePlugin = array_shift($plugins); + self::assertInstanceOf(CachePlugin::class, $cachePlugin); + + $cacheLifeTime = NSA::getProperty($cachePlugin, 'lifetime'); + self::assertNull($cacheLifeTime); + } + public function testBundleWithPluginsYml() { $kernel = $this->createKernel(); diff --git a/Tests/Functional/config/cache_without_lifetime.yml b/Tests/Functional/config/cache_without_lifetime.yml new file mode 100644 index 00000000..1c11bb00 --- /dev/null +++ b/Tests/Functional/config/cache_without_lifetime.yml @@ -0,0 +1,12 @@ +bazinga_geocoder: + profiling: + enabled: false + providers: + acme: + factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory + cache_precision: 4 + cache: acme.cache + +services: + acme.cache: + class: Bazinga\GeocoderBundle\Tests\Functional\Helper\CacheHelper