diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index c5e1fc0..51b4492 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -154,7 +154,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { * collected separately, because they need to be processed last, so as to be * able to override services from application service providers. * - * Allowing objects is for example used for allowing + * Allowing objects is for example used to allow * \Drupal\Tests\KernelTestBase to register itself as service provider. * * @var array diff --git a/core/lib/Drupal/Core/Queue/QueueMemoryFactory.php b/core/lib/Drupal/Core/Queue/QueueMemoryFactory.php deleted file mode 100644 index 97f9db5..0000000 --- a/core/lib/Drupal/Core/Queue/QueueMemoryFactory.php +++ /dev/null @@ -1,28 +0,0 @@ -setUp(); $options = $this->container->get('database')->getConnectionOptions(); - $this->assertSame('', $options['prefix']['default']); + $this->assertSame($this->databasePrefix, $options['prefix']['default']); } /** @@ -105,8 +105,7 @@ public function testSetUp() { public function testSetUpDoesNotLeak() { $this->assertArrayNotHasKey('destroy-me', $GLOBALS); - // We store the active configuration in the DB. - $expected = ['config' => 'config']; + $expected = []; $schema = $this->container->get('database')->schema(); $this->assertEquals($expected, $schema->findTables('%')); } diff --git a/core/tests/Drupal/Tests/KernelTestBase.php b/core/tests/Drupal/Tests/KernelTestBase.php index 97fb006..f3a7daa 100644 --- a/core/tests/Drupal/Tests/KernelTestBase.php +++ b/core/tests/Drupal/Tests/KernelTestBase.php @@ -46,7 +46,7 @@ * module list. * * Unlike \Drupal\simpletest\WebTestBase, the modules are only loaded, but not - * installed. Modules need to be installed manually, if needed. + * installed. Modules have to be installed manually, if needed. * * @see \Drupal\Tests\KernelTestBase::$modules * @see \Drupal\Tests\KernelTestBase::enableModules() @@ -63,7 +63,7 @@ /** * {@inheritdoc} * - * Back-up and restore any global variables that may be changed by tests. + * Back up and restore any global variables that may be changed by tests. * * @see self::runTestInSeparateProcess */ @@ -80,7 +80,7 @@ /** * {@inheritdoc} * - * Back-up and restore static class properties that may be changed by tests. + * Back up and restore static class properties that may be changed by tests. * * @see self::runTestInSeparateProcess */ @@ -91,17 +91,17 @@ * * Contains a few static class properties for performance. */ - protected $backupStaticAttributesBlacklist = array( + protected $backupStaticAttributesBlacklist = [ // Ignore static discovery/parser caches to speed up tests. - 'Drupal\Component\Discovery\YamlDiscovery' => array('parsedFiles'), - 'Drupal\Core\DependencyInjection\YamlFileLoader' => array('yaml'), - 'Drupal\Core\Extension\ExtensionDiscovery' => array('files'), - 'Drupal\Core\Extension\InfoParser' => array('parsedInfos'), + 'Drupal\Component\Discovery\YamlDiscovery' => ['parsedFiles'], + 'Drupal\Core\DependencyInjection\YamlFileLoader' => ['yaml'], + 'Drupal\Core\Extension\ExtensionDiscovery' => ['files'], + 'Drupal\Core\Extension\InfoParser' => ['parsedInfos'], // Drupal::$container cannot be serialized. - 'Drupal' => array('container'), + 'Drupal' => ['container'], // Settings cannot be serialized. - 'Drupal\Core\Site\Settings' => array('instance'), - ); + 'Drupal\Core\Site\Settings' => ['instance'], + ]; /** * {@inheritdoc} @@ -256,9 +256,7 @@ protected function bootEnvironment() { 'file_public_path' => $this->siteDirectory . '/files', // Disable Twig template caching/dumping. 'twig_cache' => FALSE, - // @todo Remove this; fix Queue factories + consuming code. // @see \Drupal\Tests\KernelTestBase::register() - 'queue_default' => 'queue.memory', ); new Settings($settings); @@ -270,7 +268,7 @@ protected function bootEnvironment() { foreach (Database::getAllConnectionInfo() as $key => $targets) { Database::removeConnection($key); } - Database::setMultipleConnectionInfo($this->getDatabaseConnectionInfo()); + Database::addConnectionInfo('default', 'default', $this->getDatabaseConnectionInfo()['default']); } protected function parseDbUrl($db_url) { @@ -343,7 +341,7 @@ private function bootKernel() { $container = $this->getCompiledContainerBuilder($modules); } - // Bootstrap the kernel. Do not use createFromRequest to retain Settings. + // Bootstrap the kernel. Do not use createFromRequest() to retain Settings. $kernel = new DrupalKernel('testing', $this->classLoader, FALSE); $kernel->setSitePath($this->siteDirectory); // Boot the precompiled container. The kernel will enhance it with synthetic @@ -414,29 +412,29 @@ protected function config($name) { * @internal */ protected function getDatabaseConnectionInfo() { - $databases['default']['default'] = array( - 'driver' => 'sqlite', - 'namespace' => 'Drupal\\Core\\Database\\Driver\\sqlite', - 'host' => '', - 'database' => ':memory:', - 'username' => '', - 'password' => '', - 'prefix' => array( - 'default' => '', - ), - ); - - // Allow to specify a custom db_url. - if ($db_url = getenv('PHPUNIT_DBURL')) { - $databases['default']['default'] = $this->parseDbUrl($db_url); + // If the test is run with argument dburl then use it. + $db_url = getenv('SIMPLETEST_DB'); + if (!empty($db_url)) { + $database = Database::convertDbUrlToConnectionInfo($db_url, $this->root); + Database::addConnectionInfo('default', 'default', $database); + } - // In the case we don't use SQLite directly we need to generate a DB - // prefix. - $suffix = mt_rand(100000, 999999); - $this->databasePrefix = 'simpletest' . $suffix; - $databases['default']['default']['prefix'] = ['default' => $this->databasePrefix]; + // Clone the current connection and replace the current prefix. + $connection_info = Database::getConnectionInfo('default'); + if (is_null($connection_info)) { + throw new \InvalidArgumentException('There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh.'); } - return $databases; + else { + Database::renameConnection('default', 'simpletest_original_default'); + foreach ($connection_info as $target => $value) { + // Replace the full table prefix definition to ensure that no table + // prefixes of the test runner leak into the test. + $connection_info[$target]['prefix'] = array( + 'default' => $value['prefix']['default'] . $this->databasePrefix, + ); + } + } + return $connection_info; } /** @@ -465,7 +463,7 @@ protected function getDatabaseConnectionInfo() { * that upstream. * 3. PhpDumper is very slow on its own. * - * @param array $modules + * @param string[] $modules * The list of modules to enable. * * @return \Drupal\Core\DependencyInjection\ContainerBuilder @@ -566,14 +564,6 @@ public function register(ContainerBuilder $container) { ->addTag('event_subscriber'); } - // @todo Missing QueueMemoryFactory + QueueFactory type hints + no interface. - // Temporarily tampering with Settings instead. - // @see \Drupal\Tests\KernelTestBase::bootEnvironment() - $container - ->register('queue.memory', 'Drupal\Core\Queue\QueueMemoryFactory'); - // $container - // ->setAlias('queue', 'queue.memory'); - if ($container->hasDefinition('path_processor_alias')) { // Prevent the alias-based path processor, which requires a url_alias db // table, from being registered to the path processor manager. We do this @@ -661,7 +651,8 @@ protected function tearDown() { $this->container = NULL; new Settings(array()); - // Destroy the in-memory database. + // Destroy the database connection, which for example removes the memory + // from sqlite in memory. foreach (Database::getAllConnectionInfo() as $key => $targets) { Database::removeConnection($key); } @@ -812,7 +803,8 @@ protected function enableModules(array $modules) { $extensions = $module_handler->getModuleList(); $this->container->get('kernel')->updateModules($extensions, $extensions); - // Ensure isLoaded() is TRUE in order to make _theme() work. + // Ensure isLoaded() is TRUE in order to make + // \Drupal\Core\Theme\ThemeManagerInterface::render() work. // Note that the kernel has rebuilt the container; this $module_handler is // no longer the $module_handler instance from above. $module_handler = $this->container->get('module_handler'); @@ -878,7 +870,7 @@ protected function disableModules(array $modules) { * The rendered string output (typically HTML). */ protected function render(array &$elements) { - $content = drupal_render($elements); + $content = $this->container->get('renderer')->render($elements); drupal_process_attached($elements); $this->setRawContent($content); $this->verbose('
' . String::checkPlain($content));