Issue #2734423 by dawehner, jibran: Convert the remaining old kernel tests over

8.2.x
Alex Pott 2016-06-15 14:29:02 +01:00
parent da40012f3b
commit 587c514da4
6 changed files with 20 additions and 34 deletions

View File

@ -20,8 +20,7 @@ use Drupal\Tests\SessionTestTrait;
/**
* Base class for Drupal tests.
*
* Do not extend this class directly; use either
* \Drupal\simpletest\WebTestBase or \Drupal\simpletest\KernelTestBase.
* Do not extend this class directly; use \Drupal\simpletest\WebTestBase.
*/
abstract class TestBase {

View File

@ -2,7 +2,7 @@
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\KernelTestBase;
use Drupal\simpletest\WebTestBase;
/**
* This test should not load since it requires a module that is not found.
@ -10,7 +10,7 @@ use Drupal\simpletest\KernelTestBase;
* @group simpletest
* @dependencies simpletest_missing_module
*/
class MissingDependentModuleUnitTest extends KernelTestBase {
class MissingDependentModuleUnitTest extends WebTestBase {
/**
* Ensure that this test will not be loaded despite its dependency.

View File

@ -127,7 +127,7 @@ class SimpleTestBrowserTest extends WebTestBase {
$tests = array(
// A KernelTestBase test.
'Drupal\system\Tests\DrupalKernel\DrupalKernelTest',
'Drupal\KernelTests\KernelTestBaseTest',
// A PHPUnit unit test.
'Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest',
// A PHPUnit functional test.

View File

@ -5,11 +5,11 @@
* Contains \Drupal\views\Tests\Plugin\PluginBaseTest.
*/
namespace Drupal\views\Tests\Plugin;
namespace Drupal\Tests\views\Kernel\Plugin;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Render\Markup;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\views\Plugin\views\PluginBase;
/**

View File

@ -1,10 +1,9 @@
<?php
namespace Drupal\system\Tests\DrupalKernel;
namespace Drupal\KernelTests\Core\DrupalKernel;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
/**
@ -14,29 +13,17 @@ use Symfony\Component\HttpFoundation\Request;
*/
class DrupalKernelTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
// DrupalKernel relies on global $config_directories and requires those
// directories to exist. Therefore, create the directories, but do not
// invoke KernelTestBase::setUp(), since that would set up further
// environment aspects, which would distort this test, because it tests
// the DrupalKernel (re-)building itself.
$this->prepareConfigDirectories();
$this->settingsSet('php_storage', array('service_container' => array(
'bin' => 'service_container',
'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage',
'directory' => DRUPAL_ROOT . '/' . $this->publicFilesDirectory . '/php',
'secret' => Settings::getHashSalt(),
)));
}
/**
* {@inheritdoc}
*/
protected function prepareConfigDirectories() {
\Drupal::setContainer($this->originalContainer);
parent::prepareConfigDirectories();
\Drupal::unsetContainer();
$this->root = static::getDrupalRoot();
$this->bootEnvironment();
}
/**
@ -56,10 +43,10 @@ class DrupalKernelTest extends KernelTestBase {
*/
protected function getTestKernel(Request $request, array $modules_enabled = NULL) {
// Manually create kernel to avoid replacing settings.
$class_loader = require DRUPAL_ROOT . '/autoload.php';
$class_loader = require $this->root . '/autoload.php';
$kernel = DrupalKernel::createFromRequest($request, $class_loader, 'testing');
$this->settingsSet('container_yamls', []);
$this->settingsSet('hash_salt', $this->databasePrefix);
$this->setSetting('container_yamls', []);
$this->setSetting('hash_salt', $this->databasePrefix);
if (isset($modules_enabled)) {
$kernel->updateModules($modules_enabled);
}
@ -158,7 +145,7 @@ class DrupalKernelTest extends KernelTestBase {
*/
public function testRepeatedBootWithDifferentEnvironment() {
$request = Request::createFromGlobals();
$class_loader = require DRUPAL_ROOT . '/autoload.php';
$class_loader = require $this->root . '/autoload.php';
$environments = [
'testing1',
@ -169,8 +156,8 @@ class DrupalKernelTest extends KernelTestBase {
foreach ($environments as $environment) {
$kernel = DrupalKernel::createFromRequest($request, $class_loader, $environment);
$this->settingsSet('container_yamls', []);
$this->settingsSet('hash_salt', $this->databasePrefix);
$this->setSetting('container_yamls', []);
$this->setSetting('hash_salt', $this->databasePrefix);
$kernel->boot();
}

View File

@ -1191,7 +1191,7 @@ abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements Ser
'kernel',
// @see \Drupal\simpletest\TestBase::prepareEnvironment()
'generatedTestFiles',
// @see \Drupal\simpletest\KernelTestBase::containerBuild()
// Properties from the old KernelTestBase class that has been removed.
'keyValueFactory',
);
if (in_array($name, $denied) || strpos($name, 'original') === 0) {