You are here

protected function TestItemsTrait::setUpMockContainer in Search API 8

Adds a container with several mock services commonly needed by our tests.

10 calls to TestItemsTrait::setUpMockContainer()
AddURLTest::setUp in tests/src/Unit/Processor/AddURLTest.php
Creates a new processor object for use in the tests.
AggregatedFieldsTest::setUp in tests/src/Unit/Processor/AggregatedFieldsTest.php
Creates a new processor object for use in the tests.
EntityStatusTest::setUp in tests/src/Unit/Processor/EntityStatusTest.php
Creates a new processor object for use in the tests.
FieldsProcessorPluginBaseTest::setUp in tests/src/Unit/Processor/FieldsProcessorPluginBaseTest.php
Creates a new processor object for use in the tests.
HighlightTest::setUp in tests/src/Unit/Processor/HighlightTest.php
Creates a new processor object for use in the tests.

... See full list

File

tests/src/Unit/Processor/TestItemsTrait.php, line 117

Class

TestItemsTrait
Provides common methods for test cases that need to create search items.

Namespace

Drupal\Tests\search_api\Unit\Processor

Code

protected function setUpMockContainer() {

  /** @var \Drupal\Tests\UnitTestCase|\Drupal\Tests\search_api\Unit\Processor\TestItemsTrait $this */
  $dataTypeManager = $this
    ->getMockBuilder('Drupal\\search_api\\DataType\\DataTypePluginManager')
    ->disableOriginalConstructor()
    ->getMock();
  $dataTypeManager
    ->method('getInstances')
    ->will($this
    ->returnValue([]));
  $moduleHandler = $this
    ->getMockBuilder('Drupal\\Core\\Extension\\ModuleHandlerInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $eventDispatcher = $this
    ->getMockBuilder(EventDispatcherInterface::class)
    ->getMock();
  $dataTypeHelper = new DataTypeHelper($moduleHandler, $eventDispatcher, $dataTypeManager);
  $entityTypeManager = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\EntityTypeManagerInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $entityFieldManager = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\EntityFieldManagerInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $entityBundleInfo = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\EntityTypeBundleInfoInterface')
    ->disableOriginalConstructor()
    ->getMock();
  $fieldsHelper = new FieldsHelper($entityTypeManager, $entityFieldManager, $entityBundleInfo, $dataTypeHelper);
  $queryHelper = $this
    ->createMock(QueryHelperInterface::class);
  $queryHelper
    ->method('createQuery')
    ->willReturnCallback(function (IndexInterface $index, array $options = []) {
    return Query::create($index, $options);
  });
  $queryHelper
    ->method('getResults')
    ->will($this
    ->returnValue([]));
  $this->container = new ContainerBuilder();
  $this->container
    ->set('plugin.manager.search_api.data_type', $dataTypeManager);
  $this->container
    ->set('search_api.data_type_helper', $dataTypeHelper);
  $this->container
    ->set('search_api.fields_helper', $fieldsHelper);
  $this->container
    ->set('search_api.query_helper', $queryHelper);
  \Drupal::setContainer($this->container);
}