Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DependencyInjection/BazingaGeocoderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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'])) {
Expand Down
25 changes: 25 additions & 0 deletions Tests/Functional/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions Tests/Functional/config/cache_without_lifetime.yml
Original file line number Diff line number Diff line change
@@ -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