Skip to content
Closed
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
7 changes: 6 additions & 1 deletion DependencyInjection/BazingaGeocoderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public function configureProviderPlugins(ContainerBuilder $container, array $con
}

if (isset($config['cache']) || isset($config['cache_lifetime']) || isset($config['cache_precision'])) {
$cacheLifetime = isset($config['cache_lifetime']) ? $config['cache_lifetime'] : null;
if (null !== $cacheLifetime) {
$cacheLifetime = (int) $cacheLifetime;
}

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 +126,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
24 changes: 24 additions & 0 deletions Tests/Functional/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ public function testBundleWithCachedProvider()
$this->assertInstanceOf(CachePlugin::class, $plugins[0]);
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation should be removed

* @test
*/
public function cache_lifetime_can_be_null_in_order_to_let_this_detail_handle_the_cache_service()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name should be consistent with others :)

{
$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
13 changes: 13 additions & 0 deletions Tests/Functional/config/cache_without_lifetime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

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