Issue #2553661 by claudiu.cristea, geertvd, dawehner, Xano, neclimdul: KernelTestBase fails to set up FileCache

8.0.x
Alex Pott 2015-09-19 16:10:17 +01:00
parent 4f435412f9
commit 0f8b5b1b4f
4 changed files with 52 additions and 1 deletions

View File

@ -153,4 +153,13 @@ class FileCache implements FileCacheInterface {
} }
} }
/**
* Resets the static cache.
*
* @todo Replace this once https://www.drupal.org/node/2260187 is in.
*/
public static function reset() {
static::$cached = [];
}
} }

View File

@ -7,6 +7,7 @@
namespace Drupal\Tests\system\Kernel\Extension; namespace Drupal\Tests\system\Kernel\Extension;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use \Drupal\Core\Extension\ModuleUninstallValidatorException; use \Drupal\Core\Extension\ModuleUninstallValidatorException;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
@ -18,6 +19,11 @@ use Drupal\KernelTests\KernelTestBase;
*/ */
class ModuleHandlerTest extends KernelTestBase { class ModuleHandlerTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system'];
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -48,7 +54,7 @@ class ModuleHandlerTest extends KernelTestBase {
* The basic functionality of retrieving enabled modules. * The basic functionality of retrieving enabled modules.
*/ */
function testModuleList() { function testModuleList() {
$module_list = array(); $module_list = ['system'];
$this->assertModuleList($module_list, 'Initial'); $this->assertModuleList($module_list, 'Initial');

View File

@ -7,6 +7,9 @@
namespace Drupal\KernelTests; namespace Drupal\KernelTests;
use Drupal\Component\FileCache\ApcuFileCacheBackend;
use Drupal\Component\FileCache\FileCache;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigImporter;
@ -214,6 +217,7 @@ abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements Ser
parent::setUp(); parent::setUp();
$this->root = static::getDrupalRoot(); $this->root = static::getDrupalRoot();
$this->initFileCache();
$this->bootEnvironment(); $this->bootEnvironment();
$this->bootKernel(); $this->bootKernel();
} }
@ -487,6 +491,32 @@ abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements Ser
return $container; return $container;
} }
/**
* Initializes the FileCache component.
*
* We can not use the Settings object in a component, that's why we have to do
* it here instead of \Drupal\Component\FileCache\FileCacheFactory.
*/
protected function initFileCache() {
$configuration = Settings::get('file_cache');
// Provide a default configuration, if not set.
if (!isset($configuration['default'])) {
$configuration['default'] = [
'class' => FileCache::class,
'cache_backend_class' => NULL,
'cache_backend_configuration' => [],
];
// @todo Use extension_loaded('apcu') for non-testbot
// https://www.drupal.org/node/2447753.
if (function_exists('apc_fetch')) {
$configuration['default']['cache_backend_class'] = ApcuFileCacheBackend::class;
}
}
FileCacheFactory::setConfiguration($configuration);
FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));
}
/** /**
* Returns Extension objects for $modules to enable. * Returns Extension objects for $modules to enable.
* *
@ -633,6 +663,9 @@ abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements Ser
} }
} }
// Clean FileCache cache.
FileCache::reset();
// Clean up statics, container, and settings. // Clean up statics, container, and settings.
if (function_exists('drupal_static_reset')) { if (function_exists('drupal_static_reset')) {
drupal_static_reset(); drupal_static_reset();

View File

@ -7,6 +7,7 @@
namespace Drupal\KernelTests; namespace Drupal\KernelTests;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
@ -91,6 +92,8 @@ class KernelTestBaseTest extends KernelTestBase {
$this->assertEquals('on', $database->query("SHOW standard_conforming_strings")->fetchField()); $this->assertEquals('on', $database->query("SHOW standard_conforming_strings")->fetchField());
$this->assertEquals('escape', $database->query("SHOW bytea_output")->fetchField()); $this->assertEquals('escape', $database->query("SHOW bytea_output")->fetchField());
} }
$this->assertNotNull(FileCacheFactory::getPrefix());
} }
/** /**