Issue #2189411 by alexpott, dawehner, longwave, quietone: Remove an unnecessary container rebuild from FunctionalTestSetupTrait

merge-requests/593/head
Lee Rowlands 2021-04-26 18:44:34 +10:00
parent 0e272ad252
commit db3ad8f8b2
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
4 changed files with 23 additions and 11 deletions

View File

@ -377,9 +377,6 @@ trait FunctionalTestSetupTrait {
*/
protected function initKernel(Request $request) {
$this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE);
// Force the container to be built from scratch instead of loaded from the
// disk. This forces us to not accidentally load the parent site.
$this->kernel->invalidateContainer();
$this->kernel->boot();
// Add our request to the stack and route context.
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));

View File

@ -44,7 +44,7 @@ trait AssertViewsCacheTagsTrait {
// active for direct rendering of views, just like for actual requests.
/** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
$request_stack = \Drupal::service('request_stack');
$request = new Request();
$request = Request::createFromGlobals();
$request->server->set('REQUEST_TIME', REQUEST_TIME);
$view->setRequest($request);
$request_stack->push($request);

View File

@ -36,11 +36,8 @@ class InstallerPerformanceTest extends BrowserTestBase {
*/
public function testInstaller() {
// Ensures that router is not rebuilt unnecessarily during the install.
// Currently it is built once during the install in install_finished() and
// once in \Drupal\Tests\BrowserTestBase::installDrupal() when
// \Drupal\Core\Test\FunctionalTestSetupTrait::resetAll() calls
// drupal_flush_all_caches()
$this->assertSame(2, \Drupal::service('core.performance.test.recorder')->getCount('event', RoutingEvents::FINISHED));
// Currently it is built once during the install in install_finished().
$this->assertSame(1, \Drupal::service('core.performance.test.recorder')->getCount('event', RoutingEvents::FINISHED));
}
}

View File

@ -12,6 +12,7 @@ use Drupal\Component\Serialization\Json;
use Drupal\Core\Database\Database;
use Drupal\Core\Test\FunctionalTestSetupTrait;
use Drupal\Core\Test\TestSetupTrait;
use Drupal\Core\Url;
use Drupal\Core\Utility\Error;
use Drupal\FunctionalTests\AssertLegacyTrait;
use Drupal\Tests\block\Traits\BlockCreationTrait;
@ -556,11 +557,28 @@ abstract class BrowserTestBase extends TestCase {
$this->prepareSettings();
$this->doInstall();
$this->initSettings();
$container = $this->initKernel(\Drupal::request());
$this->container = $container = $this->initKernel(\Drupal::request());
$this->initConfig($container);
$this->installDefaultThemeFromClassProperty($container);
$this->installModulesFromClassProperty($container);
$this->rebuildAll();
// Clear the static cache so that subsequent cache invalidations will work
// as expected.
$this->container->get('cache_tags.invalidator')->resetChecksums();
// Set the dummy query string added to all CSS and JavaScript files.
// @todo Remove in https://www.drupal.org/project/drupal/issues/3207893.
_drupal_flush_css_js();
// Generate a route to prime the url generator with the correct base url.
// @todo Remove in https://www.drupal.org/project/drupal/issues/3207896.
Url::fromRoute('<front>')->setAbsolute()->toString();
// Explicitly call register() again on the container registered in \Drupal.
// @todo This should already be called through
// DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that
// appears to be calling a different container.
$this->container->get('stream_wrapper_manager')->register();
}
/**