From be366aec48972700e5b024aab5146f3895f35eae Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Mon, 10 Jul 2023 09:16:03 +1000 Subject: [PATCH] Issue #3325571 by Murz, andypost, smustgrave, catch, larowlan: MemoryStorage fails with "Argument #1 ($array) must be of type array" error on calling function readMultiple() --- core/lib/Drupal/Core/Config/MemoryStorage.php | 1 + .../KernelTests/Core/Config/Storage/CachedStorageTest.php | 2 -- .../KernelTests/Core/Config/Storage/ConfigStorageTestBase.php | 4 ++++ .../KernelTests/Core/Config/Storage/DatabaseStorageTest.php | 3 --- .../KernelTests/Core/Config/Storage/ManagedStorageTest.php | 2 -- .../KernelTests/Core/Config/Storage/MemoryStorageTest.php | 2 -- .../Core/Config/Storage/StorageReplaceDataWrapperTest.php | 3 --- 7 files changed, 5 insertions(+), 12 deletions(-) diff --git a/core/lib/Drupal/Core/Config/MemoryStorage.php b/core/lib/Drupal/Core/Config/MemoryStorage.php index 0c02659918e..9b18c6bfacd 100644 --- a/core/lib/Drupal/Core/Config/MemoryStorage.php +++ b/core/lib/Drupal/Core/Config/MemoryStorage.php @@ -31,6 +31,7 @@ class MemoryStorage implements StorageInterface { public function __construct($collection = StorageInterface::DEFAULT_COLLECTION) { $this->collection = $collection; $this->config = new \ArrayObject(); + $this->config[$collection] = []; } /** diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php index 1374f5975cd..f7ae6cea31e 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php @@ -37,8 +37,6 @@ class CachedStorageTest extends ConfigStorageTestBase { $this->fileStorage = new FileStorage($dir); $this->storage = new CachedStorage($this->fileStorage, \Drupal::service('cache.config')); $this->cache = \Drupal::service('cache_factory')->get('config'); - // ::listAll() verifications require other configuration data to exist. - $this->storage->write('system.performance', []); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/ConfigStorageTestBase.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/ConfigStorageTestBase.php index 97b021bfded..5ac2e192c7d 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Storage/ConfigStorageTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/ConfigStorageTestBase.php @@ -39,6 +39,9 @@ abstract class ConfigStorageTestBase extends KernelTestBase { // Checking whether a non-existing name exists returns FALSE. $this->assertFalse($this->storage->exists($name)); + // Checking whether readMultiple() works with empty storage. + $this->assertEmpty($this->storage->readMultiple([$name])); + // Reading a non-existing name returns FALSE. $data = $this->storage->read($name); $this->assertFalse($data); @@ -59,6 +62,7 @@ abstract class ConfigStorageTestBase extends KernelTestBase { $this->assertTrue($result); // Listing all names returns all. + $this->storage->write('system.performance', []); $names = $this->storage->listAll(); $this->assertContains('system.performance', $names); $this->assertContains($name, $names); diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php index b26b3fd53c6..11e827bf73a 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php @@ -20,9 +20,6 @@ class DatabaseStorageTest extends ConfigStorageTestBase { $this->storage = new DatabaseStorage($this->container->get('database'), 'config'); $this->invalidStorage = new DatabaseStorage($this->container->get('database'), 'invalid'); - - // ::listAll() verifications require other configuration data to exist. - $this->storage->write('system.performance', []); } protected function read($name) { diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/ManagedStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/ManagedStorageTest.php index 66d2b6dcfe5..5f7a373e79b 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Storage/ManagedStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/ManagedStorageTest.php @@ -28,8 +28,6 @@ class ManagedStorageTest extends ConfigStorageTestBase implements StorageManager protected function setUp(): void { parent::setUp(); $this->storage = new ManagedStorage($this); - // ::listAll() verifications require other configuration data to exist. - $this->storage->write('system.performance', []); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/MemoryStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/MemoryStorageTest.php index 1f2f26a467f..79af5ff8df5 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Storage/MemoryStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/MemoryStorageTest.php @@ -17,8 +17,6 @@ class MemoryStorageTest extends ConfigStorageTestBase { protected function setUp(): void { parent::setUp(); $this->storage = new MemoryStorage(); - // ::listAll() verifications require other configuration data to exist. - $this->storage->write('system.performance', []); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/StorageReplaceDataWrapperTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/StorageReplaceDataWrapperTest.php index 397f0681597..98bd908f097 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Storage/StorageReplaceDataWrapperTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/StorageReplaceDataWrapperTest.php @@ -18,9 +18,6 @@ class StorageReplaceDataWrapperTest extends ConfigStorageTestBase { protected function setUp(): void { parent::setUp(); $this->storage = new StorageReplaceDataWrapper($this->container->get('config.storage')); - // ::listAll() verifications require other configuration data to exist. - $this->storage->write('system.performance', []); - $this->storage->replaceData('system.performance', ['foo' => 'bar']); } /**