diff --git a/core/core.services.yml b/core/core.services.yml index f0a2e9bf0ca43dac575d0c2d4fde4f5a6e358e61..cce73e7794e1deea84e11d73c276b47a2ea91466 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -4,6 +4,9 @@ parameters: # allow IDEs to autocomplete them when writing new service YAML files. app.root: '' site.path: '' + # \Drupal\Core\Cache\ListCacheBinsPass::process() will override this but defining this allows the cache system to + # function properly before that runs. + cache_default_bin_backends: [] session.storage.options: gc_probability: 1 gc_divisor: 100 diff --git a/core/modules/system/tests/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php b/core/modules/system/tests/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php index 00e00a00d154fdf6091cac3fc9a8eec27c6bd097..2e266d90ed9cf87b21055ef13ab837f0b1a7bfc8 100644 --- a/core/modules/system/tests/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php +++ b/core/modules/system/tests/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php @@ -18,6 +18,18 @@ public function alter(ContainerBuilder $container) { $definition->setClass('Drupal\service_provider_test\TestFileUsage'); } + // Make sure a cached service can be also called in a service provider. + // https://www.drupal.org/project/drupal/issues/2363351 + /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */ + $module_handler = $container->get('module_handler'); + try { + $this_module_relative_path = $module_handler->getModule('service_provider_test')->getPath(); + $container->setParameter('service_provider_test_path', $this_module_relative_path); + } + catch (\Exception $e) { + throw new \LogicException('Unable to identify installation path of this module.'); + } + if ($indicator = Settings::get('deployment_identifier')) { $container->setParameter('container_rebuild_indicator', $indicator); } diff --git a/core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php b/core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php index 3a8a0f914793982bf178580a4a17dbc4e0219862..b27f379c701c913f29f7c124bcf49eda0de202b5 100644 --- a/core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php +++ b/core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php @@ -2,7 +2,11 @@ namespace Drupal\KernelTests\Core\ServiceProvider; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\KernelTests\KernelTestBase; +use Symfony\Component\DependencyInjection\Parameter; +use Symfony\Component\DependencyInjection\Reference; +use Drupal\Core\Cache\CacheFactory; /** * Tests service provider registration to the DIC. @@ -18,6 +22,21 @@ class ServiceProviderTest extends KernelTestBase { */ protected static $modules = ['file', 'service_provider_test', 'system']; + /** + * {@inheritdoc} + */ + public function register(ContainerBuilder $container) { + parent::register($container); + // Undo cache_factory override done in parent because it can hide caching + // issues in container build time. + // @see \Drupal\service_provider_test\ServiceProviderTestServiceProvider::alter() + $this->container + ->register('cache_factory', CacheFactory::class) + ->addArgument(new Reference('settings')) + ->addArgument(new Parameter('cache_default_bin_backends')) + ->addMethodCall('setContainer', [new Reference('service_container')]); + } + /** * Tests that services provided by module service providers get registered to the DIC. */