function BackendCompilerPassTest::getMockDriverContainerWithDefaultBackendParameterArgumentAndDotPrefixedService

Creates a container with a database mock definition in it.

This mock container has a default_backend parameter and a dot-prefixed service to verify the right aliases are set.

Return value

\Symfony\Component\DependencyInjection\ContainerBuilder The container with a mock database service in it.

1 call to BackendCompilerPassTest::getMockDriverContainerWithDefaultBackendParameterArgumentAndDotPrefixedService()
BackendCompilerPassTest::testProcess in core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/BackendCompilerPassTest.php
Tests the process method.

File

core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/BackendCompilerPassTest.php, line 212

Class

BackendCompilerPassTest
@coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\BackendCompilerPass[[api-linebreak]] @group DependencyInjection

Namespace

Drupal\Tests\Core\DependencyInjection\Compiler

Code

protected function getMockDriverContainerWithDefaultBackendParameterArgumentAndDotPrefixedService() : ContainerBuilder&MockObject {
  $container = $this->getMockBuilder(ContainerBuilder::class)
    ->getMock();
  $container->expects($this->once())
    ->method('hasParameter')
    ->with('default_backend')
    ->willReturn(TRUE);
  $container->expects($this->once())
    ->method('getParameter')
    ->with('default_backend')
    ->willReturn('a_valid_default_backend');
  $mock = $this->getMockBuilder(Connection::class)
    ->disableOriginalConstructor()
    ->getMock();
  $mock->expects($this->never())
    ->method('driver');
  $mock->expects($this->never())
    ->method('databaseType');
  $container->expects($this->any())
    ->method('get')
    ->with('database')
    ->willReturn($mock);
  $container->expects($this->once())
    ->method('findTaggedServiceIds')
    ->willReturn([
    'fakeService' => [
      'class' => 'fakeServiceClass',
    ],
  ]);
  $container->expects($this->once())
    ->method('hasDefinition')
    ->with('a_valid_default_backend.fakeService')
    ->willReturn(TRUE);
  $container->expects($this->once())
    ->method('setAlias')
    ->with('fakeService', new Alias('a_valid_default_backend.fakeService'));
  return $container;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.