protected function ConfigUpdateUnitTestBase::getConfigStorageMock in Configuration Update Manager 8
Creates a mock config storage object for the test.
Parameters
string $type: Type of storage object to return: 'active', 'extension', or 'optional'. In active storage, the read() method is mocked to assume you are reading core.extension to get the profile name, so it returns that information. For extension and optional storage, the getComponentNames() method is mocked, and for all storages, the listAll() method is mocked.
See also
ConfigUpdateUnitTestBase::configStorageActiveInfo
ConfigUpdateUnitTestBase::configStorageExtensionInfo
ConfigUpdateUnitTestBase::configStorageOptionalInfo
1 call to ConfigUpdateUnitTestBase::getConfigStorageMock()
- ConfigReverterTest::setUp in tests/
src/ Unit/ ConfigReverterTest.php
File
- tests/
src/ Unit/ ConfigUpdateUnitTestBase.php, line 191
Class
- ConfigUpdateUnitTestBase
- Base class for unit testing in Config Update Manager.
Namespace
Drupal\Tests\config_update\UnitCode
protected function getConfigStorageMock($type) {
if ($type == 'active') {
$storage = $this
->getMockBuilder('Drupal\\Core\\Config\\StorageInterface')
->getMock();
// Various tests assume various values of configuration that need to be
// read from active storage.
$map = [
[
'core.extension',
[
'profile' => 'standard',
],
],
[
'foo.bar.one',
[
'foo.bar.one' => 'active',
'id' => 'one',
],
],
[
'missing',
FALSE,
],
[
'in.extension',
[
'in.extension' => 'active',
'_core' => 'core_for_in.extension',
],
],
[
'in.both',
[
'in.both' => 'active',
],
],
[
'in.optional',
[
'in.optional' => 'active',
],
],
];
$storage
->method('read')
->will($this
->returnValueMap($map));
$storage
->method('listAll')
->will($this
->returnValueMap($this->configStorageActiveInfo));
}
elseif ($type == 'extension') {
$storage = $this
->getMockBuilder('Drupal\\Core\\Config\\ExtensionInstallStorage')
->disableOriginalConstructor()
->getMock();
$value = [];
foreach ($this->configStorageExtensionInfo[2][1] as $item) {
$value[$item] = 'ignored';
}
$storage
->method('getComponentNames')
->willReturn($value);
$storage
->method('listAll')
->will($this
->returnValueMap($this->configStorageExtensionInfo));
$map = [
[
'in.extension',
[
'in.extension' => 'extension',
],
],
[
'in.both',
[
'in.both' => 'extension',
],
],
[
'in.optional',
FALSE,
],
[
'foo.bar.one',
[
'foo.bar.one' => 'extension',
'id' => 'one',
],
],
[
'another',
[
'another' => 'extension',
'id' => 'one',
],
],
[
'missing2',
FALSE,
],
];
$storage
->method('read')
->will($this
->returnValueMap($map));
}
else {
$storage = $this
->getMockBuilder('Drupal\\Core\\Config\\ExtensionInstallStorage')
->disableOriginalConstructor()
->getMock();
$value = [];
foreach ($this->configStorageOptionalInfo[2][1] as $item) {
$value[$item] = 'ignored';
}
$storage
->method('getComponentNames')
->willReturn($value);
$storage
->method('listAll')
->will($this
->returnValueMap($this->configStorageOptionalInfo));
$map = [
[
'in.optional',
[
'in.optional' => 'optional',
],
],
[
'in.both',
[
'in.both' => 'optional',
],
],
[
'missing2',
FALSE,
],
];
$storage
->method('read')
->will($this
->returnValueMap($map));
}
return $storage;
}