Returns a stub config factory that behaves according to the passed in array.
Use this to generate a config factory that will return the desired values for the given config names.
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.
\PHPUnit_Framework_MockObject_MockBuilder A MockBuilder object for the ConfigFactory with the desired return values.
public function getConfigFactoryStub($configs) {
$config_map = array();
// Construct the desired configuration object stubs, each with its own
// desired return map.
foreach ($configs as $config_name => $config_values) {
$config_object = $this
->getMockBuilder('Drupal\\Core\\Config\\Config')
->disableOriginalConstructor()
->getMock();
$map = array();
foreach ($config_values as $key => $value) {
$map[] = array(
$key,
$value,
);
}
// Also allow to pass in no argument.
$map[] = array(
'',
$config_values,
);
$config_object
->expects($this
->any())
->method('get')
->will($this
->returnValueMap($map));
$config_map[] = array(
$config_name,
$config_object,
);
}
// Construct a config factory with the array of configuration object stubs
// as its return map.
$config_factory = $this
->getMockBuilder('Drupal\\Core\\Config\\ConfigFactory')
->disableOriginalConstructor()
->getMock();
$config_factory
->expects($this
->any())
->method('get')
->will($this
->returnValueMap($config_map));
return $config_factory;
}