Commit bb2b90af authored by catch's avatar catch

Issue #1874694 by damiankloip, chx: DrupalUnitTestBase breaks state().

parent 8ad67af2
......@@ -12,6 +12,13 @@
*/
class KeyValueMemoryFactory {
/**
* An array of keyvalue collections that are stored in memory.
*
* @var array
*/
protected $collections = array();
/**
* Constructs a new key/value memory storage object for a given collection name.
*
......@@ -21,6 +28,9 @@ class KeyValueMemoryFactory {
* A key/value store implementation for the given $collection.
*/
public function get($collection) {
return new MemoryStorage($collection);
if (!isset($this->collections[$collection])) {
$this->collections[$collection] = new MemoryStorage($collection);
}
return $this->collections[$collection];
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\simpletest;
use Drupal\Core\DrupalKernel;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Symfony\Component\DependencyInjection\Reference;
use Drupal\Core\Database\Database;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -65,6 +66,13 @@ abstract class DrupalUnitTestBase extends UnitTestBase {
private $themeFiles;
private $themeData;
/**
* A KeyValueMemoryFactory instance to use when building the container.
*
* @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory.
*/
protected $keyValueFactory;
/**
* Sets up Drupal unit test environment.
*
......@@ -79,6 +87,8 @@ protected function setUp() {
$this->themeData = state()->get('system.theme.data') ?: array();
}
$this->keyValueFactory = new KeyValueMemoryFactory();
parent::setUp();
// Build a minimal, partially mocked environment for unit tests.
$this->containerBuild(drupal_container());
......@@ -128,8 +138,7 @@ public function containerBuild($container) {
->register('config.storage', 'Drupal\Core\Config\FileStorage')
->addArgument($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]);
$conf['keyvalue_default'] = 'keyvalue.memory';
$container
->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
$container->set('keyvalue.memory', $this->keyValueFactory);
if (!$container->has('keyvalue')) {
// TestBase::setUp puts a completely empty container in
// drupal_container() which is somewhat the mirror of the empty
......
......@@ -883,11 +883,6 @@ protected function prepareEnvironment() {
unset($GLOBALS['theme_key']);
unset($GLOBALS['theme']);
// Re-initialize the theme to ensure that tests do not see an inconsistent
// behavior when calling functions that would initialize the theme if it has
// not been initialized yet.
drupal_theme_initialize();
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', $this->public_files_directory . '/error.log');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment