Commit 0858e935 authored by alexpott's avatar alexpott

Issue #2907169 by Mile23, Jo Fitzgerald: Break KernelTestBase dependency on...

Issue #2907169 by Mile23, Jo Fitzgerald: Break KernelTestBase dependency on Simpletest, deprecate stub BC traits
parent 0e6031f8
......@@ -14,6 +14,7 @@
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\Language\Language;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\TestServiceProvider;
use Symfony\Component\DependencyInjection\Parameter;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Symfony\Component\DependencyInjection\Reference;
......@@ -198,7 +199,7 @@ protected function setUp() {
// Add this test class as a service provider.
// @todo Remove the indirection; implement ServiceProviderInterface instead.
$GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
$GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = TestServiceProvider::class;
// Bootstrap a new kernel.
$class_loader = require DRUPAL_ROOT . '/autoload.php';
......
......@@ -2,111 +2,15 @@
namespace Drupal\simpletest;
use Drupal\Core\Routing\PreloadableRouteProviderInterface;
use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\KernelTests\RouteProvider as CoreRouteProvider;
/**
* Rebuilds the router when the provider is instantiated.
*
* @todo Move this outside of simpletest namespace to the Drupal\Tests, see
* https://www.drupal.org/node/2672762
* @deprecated in 8.6.0 for removal before 9.0.0. Use
* Drupal\KernelTests\RouteProvider instead.
*
* @see https://www.drupal.org/node/2943146
*/
class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
/**
* Loads the real route provider from the container and rebuilds the router.
*
* @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface
* The route provider.
*/
protected function lazyLoadItself() {
if (!isset($this->service)) {
$container = \Drupal::getContainer();
$this->service = $container->get('simpletest.router.route_provider');
$container->get('router.builder')->rebuild();
}
return $this->service;
}
/**
* {@inheritdoc}
*/
public function getRouteCollectionForRequest(Request $request) {
return $this->lazyLoadItself()->getRouteCollectionForRequest($request);
}
/**
* {@inheritdoc}
*/
public function getRouteByName($name) {
return $this->lazyLoadItself()->getRouteByName($name);
}
/**
* {@inheritdoc}
*/
public function preLoadRoutes($names) {
return $this->lazyLoadItself()->preLoadRoutes($names);
}
/**
* {@inheritdoc}
*/
public function getRoutesByNames($names) {
return $this->lazyLoadItself()->getRoutesByNames($names);
}
/**
* {@inheritdoc}
*/
public function getCandidateOutlines(array $parts) {
return $this->lazyLoadItself()->getCandidateOutlines($parts);
}
/**
* {@inheritdoc}
*/
public function getRoutesByPattern($pattern) {
return $this->lazyLoadItself()->getRoutesByPattern($pattern);
}
/**
* {@inheritdoc}
*/
public function routeProviderRouteCompare(array $a, array $b) {
return $this->lazyLoadItself()->routeProviderRouteCompare($a, $b);
}
/**
* {@inheritdoc}
*/
public function getAllRoutes() {
return $this->lazyLoadItself()->getAllRoutes();
}
/**
* {@inheritdoc}
*/
public function reset() {
return $this->lazyLoadItself()->reset();
}
/**
* {@inheritdoc}
*/
public function getRoutesPaged($offset, $length = NULL) {
return $this->lazyLoadItself()->getRoutesPaged($offset, $length);
}
/**
* {@inheritdoc}
*/
public function getRoutesCount() {
return $this->lazyLoadItself()->getRoutesCount();
}
class RouteProvider extends CoreRouteProvider {
}
......@@ -2,54 +2,16 @@
namespace Drupal\simpletest;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Symfony\Component\DependencyInjection\Definition;
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) {
foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
// While $container->get() does a recursive resolve, getDefinition() does
// not, so do it ourselves.
// @todo Make the code more readable in
// https://www.drupal.org/node/2911498.
for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id)) {
}
$definition = $container->getDefinition($id);
$definition->clearTag('needs_destruction');
$container->setDefinition("simpletest.$original_id", $definition);
$container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
}
}
use Drupal\KernelTests\TestServiceProvider as CoreTestServiceProvider;
/**
* Provides special routing services for tests.
*
* @deprecated in 8.6.0 for removal before Drupal 9.0.0. Use
* Drupal\KernelTests\TestServiceProvider instead.
*
* @see https://www.drupal.org/node/2943146
*/
class TestServiceProvider extends CoreTestServiceProvider {
}
This diff is collapsed.
......@@ -17,13 +17,11 @@
use Drupal\Core\Language\Language;
use Drupal\Core\Site\Settings;
use Drupal\Core\Test\TestDatabase;
use Drupal\simpletest\AssertContentTrait;
use Drupal\Tests\AssertHelperTrait;
use Drupal\Tests\ConfigTestTrait;
use Drupal\Tests\PhpunitCompatibilityTrait;
use Drupal\Tests\RandomGeneratorTrait;
use Drupal\Tests\TestRequirementsTrait;
use Drupal\simpletest\TestServiceProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
......
<?php
namespace Drupal\KernelTests;
use Drupal\Core\Routing\PreloadableRouteProviderInterface;
use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Rebuilds the router when the provider is instantiated.
*/
class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
/**
* Loads the real route provider from the container and rebuilds the router.
*
* @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface
* The route provider.
*/
protected function lazyLoadItself() {
if (!isset($this->service)) {
$container = \Drupal::getContainer();
$this->service = $container->get('simpletest.router.route_provider');
$container->get('router.builder')->rebuild();
}
return $this->service;
}
/**
* {@inheritdoc}
*/
public function getRouteCollectionForRequest(Request $request) {
return $this->lazyLoadItself()->getRouteCollectionForRequest($request);
}
/**
* {@inheritdoc}
*/
public function getRouteByName($name) {
return $this->lazyLoadItself()->getRouteByName($name);
}
/**
* {@inheritdoc}
*/
public function preLoadRoutes($names) {
return $this->lazyLoadItself()->preLoadRoutes($names);
}
/**
* {@inheritdoc}
*/
public function getRoutesByNames($names) {
return $this->lazyLoadItself()->getRoutesByNames($names);
}
/**
* {@inheritdoc}
*/
public function getCandidateOutlines(array $parts) {
return $this->lazyLoadItself()->getCandidateOutlines($parts);
}
/**
* {@inheritdoc}
*/
public function getRoutesByPattern($pattern) {
return $this->lazyLoadItself()->getRoutesByPattern($pattern);
}
/**
* {@inheritdoc}
*/
public function routeProviderRouteCompare(array $a, array $b) {
return $this->lazyLoadItself()->routeProviderRouteCompare($a, $b);
}
/**
* {@inheritdoc}
*/
public function getAllRoutes() {
return $this->lazyLoadItself()->getAllRoutes();
}
/**
* {@inheritdoc}
*/
public function reset() {
return $this->lazyLoadItself()->reset();
}
/**
* {@inheritdoc}
*/
public function getRoutesPaged($offset, $length = NULL) {
return $this->lazyLoadItself()->getRoutesPaged($offset, $length);
}
/**
* {@inheritdoc}
*/
public function getRoutesCount() {
return $this->lazyLoadItself()->getRoutesCount();
}
}
<?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.
// @todo Make the code more readable in
// https://www.drupal.org/node/2911498.
for ($id = $route_provider_service_name; $container->hasAlias($id); $id = (string) $container->getAlias($id)) {
}
$definition = $container->getDefinition($id);
$definition->clearTag('needs_destruction');
$container->setDefinition("simpletest.$route_provider_service_name", $definition);
$container->setDefinition($id, new Definition(RouteProvider::class));
}
}
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