Skip to content

Commit c080129

Browse files
norkunasNyholm
authored andcommitted
Allow cache lifetime as null (#249)
1 parent 88f7847 commit c080129

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

DependencyInjection/BazingaGeocoderExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con
112112
}
113113

114114
if (isset($config['cache']) || isset($config['cache_lifetime']) || isset($config['cache_precision'])) {
115+
$cacheLifetime = isset($config['cache_lifetime']) ? (int) $config['cache_lifetime'] : null;
116+
115117
if (null === $cacheServiceId = $config['cache']) {
116118
if (!$container->has('app.cache')) {
117119
throw new \LogicException('You need to specify a service for cache.');
@@ -121,7 +123,7 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con
121123
$plugins[] = $providerServiceId.'.cache';
122124
$container->register($providerServiceId.'.cache', CachePlugin::class)
123125
->setPublic(false)
124-
->setArguments([new Reference($cacheServiceId), (int) $config['cache_lifetime'], $config['cache_precision']]);
126+
->setArguments([new Reference($cacheServiceId), $cacheLifetime, $config['cache_precision']]);
125127
}
126128

127129
if (isset($config['limit'])) {

Tests/Functional/BundleInitializationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ public function testBundleWithCachedProvider()
8989
$this->assertInstanceOf(CachePlugin::class, $plugins[0]);
9090
}
9191

92+
public function testCacheLifetimeCanBeNull()
93+
{
94+
$kernel = $this->createKernel();
95+
$kernel->addConfigFile(__DIR__.'/config/cache_without_lifetime.yml');
96+
97+
$this->bootKernel();
98+
99+
$container = $this->getContainer();
100+
101+
self::assertTrue($container->has('bazinga_geocoder.provider.acme'));
102+
103+
/** @var PluginProvider $service */
104+
$service = $container->get('bazinga_geocoder.provider.acme');
105+
self::assertInstanceOf(PluginProvider::class, $service);
106+
107+
$plugins = NSA::getProperty($service, 'plugins');
108+
self::assertCount(1, $plugins);
109+
110+
$cachePlugin = array_shift($plugins);
111+
self::assertInstanceOf(CachePlugin::class, $cachePlugin);
112+
113+
$cacheLifeTime = NSA::getProperty($cachePlugin, 'lifetime');
114+
self::assertNull($cacheLifeTime);
115+
}
116+
92117
public function testBundleWithPluginsYml()
93118
{
94119
$kernel = $this->createKernel();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bazinga_geocoder:
2+
profiling:
3+
enabled: false
4+
providers:
5+
acme:
6+
factory: Bazinga\GeocoderBundle\ProviderFactory\GoogleMapsFactory
7+
cache_precision: 4
8+
cache: acme.cache
9+
10+
services:
11+
acme.cache:
12+
class: Bazinga\GeocoderBundle\Tests\Functional\Helper\CacheHelper

0 commit comments

Comments
 (0)