Commit 28db985e authored by catch's avatar catch
Browse files

Issue #2363351 by mxr576, chx, Berdir, Fabianx, alexpott, Alan Evans,...

Issue #2363351 by mxr576, chx, Berdir, Fabianx, alexpott, Alan Evans, dawehner, larowlan: Cached services can't be used in service providers/modifiers
parent 6433401c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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
+12 −0
Original line number Diff line number Diff line
@@ -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);
    }
+19 −0
Original line number Diff line number Diff line
@@ -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.
   */