You are here

protected function ContainerTest::getMockContainerDefinition in Service Container 7.2

Same name and namespace in other branches
  1. 7 tests/src/DependencyInjection/ContainerTest.php \Drupal\Tests\service_container\DependencyInjection\ContainerTest::getMockContainerDefinition()

Returns a mock container definition.

Return value

array Associated array with parameters and services.

1 call to ContainerTest::getMockContainerDefinition()
ContainerTest::setUp in tests/src/DependencyInjection/ContainerTest.php

File

tests/src/DependencyInjection/ContainerTest.php, line 401
Contains \Drupal\Tests\service_container\DependencyInjection\ContainerTest

Class

ContainerTest
@coversDefaultClass \Drupal\service_container\DependencyInjection\Container @group dic

Namespace

Drupal\Tests\service_container\DependencyInjection

Code

protected function getMockContainerDefinition() {
  $fake_service = Mockery::mock('alias:Drupal\\Tests\\service_container\\DependencyInjection\\FakeService');
  $parameters = array();
  $parameters['some_private_config'] = 'really_private_lama';
  $parameters['some_config'] = 'foo';
  $parameters['some_other_config'] = 'lama';
  $parameters['factory_service_class'] = get_class($fake_service);
  $services = array();
  $services['service_container'] = array(
    'class' => '\\Drupal\\service_container\\DependencyInjection\\Container',
  );
  $services['other.service'] = array(
    // @todo Support parameter expansion for classes.
    'class' => get_class($fake_service),
  );
  $services['late.service'] = array(
    'class' => get_class($fake_service),
  );
  $services['service.provider'] = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      '@other.service',
      '%some_config%',
    ),
    'properties' => array(
      '_someProperty' => 'foo',
    ),
    'calls' => array(
      array(
        'setContainer',
        array(
          '@service_container',
        ),
      ),
      array(
        'setOtherConfigParameter',
        array(
          '%some_other_config%',
        ),
      ),
    ),
    'priority' => 0,
  );
  $private_service = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      '@other.service',
      '%some_private_config%',
    ),
    'public' => FALSE,
  );
  $private_hash = sha1(serialize($private_service));
  $services['service_using_private'] = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      (object) array(
        'type' => 'private_service',
        'value' => $private_service,
        'id' => 'private__' . $private_hash,
      ),
      '%some_config%',
    ),
  );
  $services['service_using_array'] = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      array(
        '@other.service',
      ),
      '%some_private_config%',
    ),
  );
  $services['service_with_optional_dependency'] = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      '@?service.does_not_exist',
      '%some_private_config%',
    ),
  );
  $services['factory_service'] = array(
    'class' => '\\Drupal\\service_container\\ServiceContainer\\ControllerInterface',
    'factory_method' => 'getFactoryMethod',
    'factory_service' => 'service.provider',
    'arguments' => array(
      '%factory_service_class%',
    ),
  );
  $services['factory_class'] = array(
    'class' => '\\Drupal\\service_container\\ServiceContainer\\ControllerInterface',
    'factory_method' => 'getFactoryMethod',
    'factory_class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
      array(
        NULL,
        'bar',
      ),
    ),
    'calls' => array(
      array(
        'setContainer',
        array(
          '@service_container',
        ),
      ),
    ),
  );
  $services['factory_service_new'] = array(
    'class' => '\\Drupal\\service_container\\ServiceContainer\\ControllerInterface',
    'factory' => array(
      '@service.provider',
      'getFactoryMethod',
    ),
    'arguments' => array(
      '%factory_service_class%',
    ),
  );
  $services['factory_class_new'] = array(
    'class' => '\\Drupal\\service_container\\ServiceContainer\\ControllerInterface',
    'factory' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService::getFactoryMethod',
    'arguments' => array(
      '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
      array(
        NULL,
        'bar',
      ),
    ),
    'calls' => array(
      array(
        'setContainer',
        array(
          '@service_container',
        ),
      ),
    ),
  );
  $services['wrong_factory'] = array(
    'class' => '\\Drupal\\service_container\\ServiceContainer\\ControllerInterface',
    'factory_method' => 'getFactoryMethod',
  );
  $services['circular_dependency'] = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      '@circular_dependency',
    ),
  );
  $services['service_parameter_not_exists'] = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      '@service.provider',
      '%not_exists%',
      -1,
    ),
  );
  $services['service_dependency_not_exists'] = array(
    'class' => '\\Drupal\\Tests\\service_container\\DependencyInjection\\MockService',
    'arguments' => array(
      '@service_not_exists',
      '%some_config%',
    ),
  );
  return array(
    'parameters' => $parameters,
    'services' => $services,
    'aliases' => array(
      'service.provider_alias' => 'service.provider',
    ),
  );
}