Commit 92988369 authored by catch's avatar catch
Browse files

Issue #3204002 by longwave, paulocs, daffie, catch, larowlan, alexpott:...

Issue #3204002 by longwave, paulocs, daffie, catch, larowlan, alexpott: TestServiceProvider has unused code referring to Simpletest
parent 2dd115fe
......@@ -4,9 +4,7 @@
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\StreamWrapper\PublicStream;
use Symfony\Component\DependencyInjection\Reference;
/**
* Tests CachedStorage operations.
......@@ -80,15 +78,4 @@ protected function delete($name) {
unlink($this->fileStorage->getFilePath($name));
}
/**
* {@inheritdoc}
*/
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
// Use the regular database cache backend to aid testing.
$container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory')
->addArgument(new Reference('database'))
->addArgument(new Reference('cache_tags.invalidator.checksum'));
}
}
......@@ -25,6 +25,7 @@
use Drupal\TestTools\TestVarDumper;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
use org\bovigo\vfs\vfsStream;
......@@ -575,7 +576,22 @@ public function register(ContainerBuilder $container) {
$container->getDefinition('password')
->setArguments([1]);
}
TestServiceProvider::addRouteProvider($container);
// Add the on demand rebuild route provider service.
$route_provider_service_name = 'router.route_provider';
// While $container->get() does a recursive resolve, getDefinition() does
// not, so do it ourselves.
$id = $route_provider_service_name;
while ($container->hasAlias($id)) {
$id = (string) $container->getAlias($id);
}
$definition = $container->getDefinition($id);
$definition->clearTag('needs_destruction');
$container->setDefinition("simpletest.$route_provider_service_name", $definition);
$route_provider_definition = new Definition(RouteProvider::class);
$route_provider_definition->setPublic(TRUE);
$container->setDefinition($id, $route_provider_definition);
}
/**
......
<?php
namespace Drupal\KernelTests;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Symfony\Component\DependencyInjection\Definition;
/**
* Provides special routing services for tests.
*/
class TestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
/**
* @var \Drupal\simpletest\TestBase
*/
public static $currentTest;
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
if (static::$currentTest && method_exists(static::$currentTest, 'containerBuild')) {
static::$currentTest->containerBuild($container);
}
}
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
if (static::$currentTest instanceof KernelTestBase) {
static::addRouteProvider($container);
}
}
/**
* Add the on demand rebuild route provider service.
*
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
*/
public static function addRouteProvider(ContainerBuilder $container) {
$route_provider_service_name = 'router.route_provider';
// While $container->get() does a recursive resolve, getDefinition() does
// not, so do it ourselves.
$id = $route_provider_service_name;
while ($container->hasAlias($id)) {
$id = (string) $container->getAlias($id);
}
$definition = $container->getDefinition($id);
$definition->clearTag('needs_destruction');
$container->setDefinition("simpletest.$route_provider_service_name", $definition);
$route_provider_definition = new Definition(RouteProvider::class);
$route_provider_definition->setPublic(TRUE);
$container->setDefinition($id, $route_provider_definition);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment