protected function WebTest::setUp in Redis 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ WebTest.php, line 37
Class
- WebTest
- Tests complex processes like installing modules with redis backends.
Namespace
Drupal\Tests\redis\FunctionalCode
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_breadcrumb_block');
$this
->drupalPlaceBlock('local_tasks_block');
// Set in-memory settings.
$settings = Settings::getAll();
// Get REDIS_INTERFACE env variable.
$redis_interface = self::getRedisInterfaceEnv();
$settings['redis.connection']['interface'] = $redis_interface;
$settings['redis_compress_length'] = 100;
$settings['cache'] = [
'default' => 'cache.backend.redis',
];
$settings['container_yamls'][] = drupal_get_path('module', 'redis') . '/example.services.yml';
$settings['bootstrap_container_definition'] = [
'parameters' => [],
'services' => [
'redis.factory' => [
'class' => 'Drupal\\redis\\ClientFactory',
],
'cache.backend.redis' => [
'class' => 'Drupal\\redis\\Cache\\CacheBackendFactory',
'arguments' => [
'@redis.factory',
'@cache_tags_provider.container',
'@serialization.phpserialize',
],
],
'cache.container' => [
'class' => '\\Drupal\\redis\\Cache\\PhpRedis',
'factory' => [
'@cache.backend.redis',
'get',
],
'arguments' => [
'container',
],
],
'cache_tags_provider.container' => [
'class' => 'Drupal\\redis\\Cache\\RedisCacheTagsChecksum',
'arguments' => [
'@redis.factory',
],
],
'serialization.phpserialize' => [
'class' => 'Drupal\\Component\\Serialization\\PhpSerialize',
],
],
];
new Settings($settings);
// Write the containers_yaml update by hand, since writeSettings() doesn't
// support some of the definitions.
$filename = $this->siteDirectory . '/settings.php';
chmod($filename, 0666);
$contents = file_get_contents($filename);
// Add the container_yaml and cache definition.
$contents .= "\n\n" . '$settings["container_yamls"][] = "' . drupal_get_path('module', 'redis') . '/example.services.yml";';
$contents .= "\n\n" . '$settings["cache"] = ' . var_export($settings['cache'], TRUE) . ';';
$contents .= "\n\n" . '$settings["redis_compress_length"] = 100;';
// Add the classloader.
$contents .= "\n\n" . '$class_loader->addPsr4(\'Drupal\\\\redis\\\\\', \'' . drupal_get_path('module', 'redis') . '/src\');';
// Add the bootstrap container definition.
$contents .= "\n\n" . '$settings["bootstrap_container_definition"] = ' . var_export($settings['bootstrap_container_definition'], TRUE) . ';';
file_put_contents($filename, $contents);
OpCodeCache::invalidate(DRUPAL_ROOT . '/' . $filename);
// Reset the cache factory.
$this->container
->set('cache.factory', NULL);
$this
->rebuildContainer();
// Get database schema.
$db_schema = Database::getConnection()
->schema();
// Make sure that the cache and lock tables aren't used.
$db_schema
->dropTable('cache_default');
$db_schema
->dropTable('cache_render');
$db_schema
->dropTable('cache_config');
$db_schema
->dropTable('cache_container');
$db_schema
->dropTable('cachetags');
$db_schema
->dropTable('semaphore');
$db_schema
->dropTable('flood');
}