function RecipeConfigStorageWrapperTest::testMultipleStorages

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Recipe/RecipeConfigStorageWrapperTest.php \Drupal\Tests\Core\Recipe\RecipeConfigStorageWrapperTest::testMultipleStorages()

Validate that multiple storages return underlying values correctly.

File

core/tests/Drupal/Tests/Core/Recipe/RecipeConfigStorageWrapperTest.php, line 43

Class

RecipeConfigStorageWrapperTest
@coversDefaultClass \Drupal\Core\Recipe\RecipeConfigStorageWrapper @group Recipe

Namespace

Drupal\Tests\Core\Recipe

Code

public function testMultipleStorages() : void {
    $a = new MemoryStorage();
    $a->write('a_key', [
        'a_data_first',
    ]);
    $b = new MemoryStorage();
    // Add a conflicting key so that we can test the first value is returned.
    $b->write('a_key', [
        'a_data_second',
    ]);
    $b->write('b_key', [
        'b_data',
    ]);
    // We test with a third storage as well since only two storages can be done
    // via the constructor alone.
    $c = new MemoryStorage();
    $c->write('c_key', [
        'c_data',
    ]);
    $storages = [
        $a,
        $b,
        $c,
    ];
    $wrapped = RecipeConfigStorageWrapper::createStorageFromArray($storages);
    $this->assertSame($a->read('a_key'), $wrapped->read('a_key'));
    $this->assertNotEquals($b->read('a_key'), $wrapped->read('a_key'));
    $this->assertSame($b->read('b_key'), $wrapped->read('b_key'));
    $this->assertSame($c->read('c_key'), $wrapped->read('c_key'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.