function BackendCompilerPassTest::getMockDriverContainerWithNullDriverBackend

Creates a container with a database mock definition in it.

This mock won't declare a driver nor databaseType to ensure no invalid aliases are set.

Return value

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

1 call to BackendCompilerPassTest::getMockDriverContainerWithNullDriverBackend()
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 178

Class

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

Namespace

Drupal\Tests\Core\DependencyInjection\Compiler

Code

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

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