Issue #3056617 by jcisio, tstoeckler, alexpott: NullStorage does not support collection

merge-requests/2419/head
Alex Pott 2019-11-29 12:17:26 +00:00
parent a0ebbf57de
commit cd325f157a
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
2 changed files with 49 additions and 2 deletions

View File

@ -18,6 +18,24 @@ namespace Drupal\Core\Config;
*/ */
class NullStorage implements StorageInterface { class NullStorage implements StorageInterface {
/**
* The storage collection.
*
* @var string
*/
protected $collection;
/**
* Constructs a new NullStorage.
*
* @param string $collection
* (optional) The collection to store configuration in. Defaults to the
* default collection.
*/
public function __construct($collection = StorageInterface::DEFAULT_COLLECTION) {
$this->collection = $collection;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -92,13 +110,14 @@ class NullStorage implements StorageInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createCollection($collection) { public function createCollection($collection) {
// No op. return new static($collection);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getAllCollectionNames() { public function getAllCollectionNames() {
// Returns only non empty collections.
return []; return [];
} }
@ -106,7 +125,7 @@ class NullStorage implements StorageInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCollectionName() { public function getCollectionName() {
return ''; return $this->collection;
} }
} }

View File

@ -0,0 +1,28 @@
<?php
namespace Drupal\Tests\Core\Config;
use Drupal\Core\Config\NullStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Tests\UnitTestCase;
/**
* Tests the NullStorage.
*
* @group Config
*/
class NullStorageTest extends UnitTestCase {
/**
* Test createCollection.
*/
public function testCollection() {
$nullStorage = new NullStorage();
$collection = $nullStorage->createCollection('test');
$this->assertInstanceOf(StorageInterface::class, $collection);
$this->assertEquals(StorageInterface::DEFAULT_COLLECTION, $nullStorage->getCollectionName());
$this->assertEquals('test', $collection->getCollectionName());
$this->assertArrayEquals([], $collection->getAllCollectionNames());
}
}