public function UnitTestCase::getConfigFactoryStub

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.

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

\PHPUnit_Framework_MockObject_MockBuilder A MockBuilder object for the ConfigFactory with the desired return values.

3 calls to UnitTestCase::getConfigFactoryStub()
PathProcessorTest::testProcessInbound in drupal/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
Tests resolving the inbound path to the system path.
RolesRidTest::testTitleQuery in drupal/core/modules/user/tests/Drupal/Tests/user/Views/Argument/RolesRidTest.php
Tests the title_query method.
UrlGeneratorTest::setUp in drupal/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php

File

drupal/core/tests/Drupal/Tests/UnitTestCase.php, line 79
Contains \Drupal\Tests\UnitTestCase.

Class

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

Namespace

Drupal\Tests

Code

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;
}