function UnitTestCase::getConfigStorageStub

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getConfigStorageStub()
  2. 8.9.x core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getConfigStorageStub()
  3. 10 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getConfigStorageStub()

Returns a stub config storage that returns the supplied configuration.

Parameters

array $configs: An associative array of configuration settings whose keys are configuration object names and whose values are key => value arrays for the configuration object in question.

Return value

\Drupal\Core\Config\StorageInterface A mocked config storage.

File

core/tests/Drupal/Tests/UnitTestCase.php, line 144

Class

UnitTestCase
Provides a base class and helpers for Drupal unit tests.

Namespace

Drupal\Tests

Code

public function getConfigStorageStub(array $configs) {
    $config_storage = $this->createMock('Drupal\\Core\\Config\\NullStorage');
    $config_storage->expects($this->any())
        ->method('listAll')
        ->willReturn(array_keys($configs));
    foreach ($configs as $name => $config) {
        $config_storage->expects($this->any())
            ->method('read')
            ->with($this->equalTo($name))
            ->willReturn($config);
    }
    return $config_storage;
}

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