FixGetConfigFactoryStubTrait.php in Purge 8.3
File
tests/src/Unit/FixGetConfigFactoryStubTrait.php
View source
<?php
namespace Drupal\Tests\purge\Unit;
trait FixGetConfigFactoryStubTrait {
public function getConfigFactoryStub(array $configs = []) {
$config_get_map = [];
$config_editable_map = [];
foreach ($configs as $config_name => $config_values) {
$map = [];
foreach ($config_values as $key => $value) {
$map[] = [
$key,
$value,
];
}
$map[] = [
'',
$config_values,
];
$immutable_config_object = $this
->getMockBuilder('Drupal\\Core\\Config\\ImmutableConfig')
->disableOriginalConstructor()
->getMock();
$immutable_config_object
->expects($this
->any())
->method('get')
->will($this
->returnValueMap($map));
$config_get_map[] = [
$config_name,
$immutable_config_object,
];
$mutable_config_object = $this
->getMockBuilder('Drupal\\Core\\Config\\Config')
->disableOriginalConstructor()
->getMock();
$mutable_config_object
->expects($this
->any())
->method('get')
->will($this
->returnValueMap($map));
$mutable_config_object
->expects($this
->any())
->method('set')
->will($this
->returnValue($mutable_config_object));
$mutable_config_object
->expects($this
->any())
->method('save')
->will($this
->returnValue($mutable_config_object));
$config_editable_map[] = [
$config_name,
$mutable_config_object,
];
}
$config_factory = $this
->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
$config_factory
->expects($this
->any())
->method('get')
->will($this
->returnValueMap($config_get_map));
$config_factory
->expects($this
->any())
->method('getEditable')
->will($this
->returnValueMap($config_editable_map));
return $config_factory;
}
}