You are here

protected function ItemFieldTest::setUp in Search API 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/ItemFieldTest.php, line 29

Class

ItemFieldTest
Tests functionality of the field class.

Namespace

Drupal\Tests\search_api\Unit

Code

protected function setUp() {
  parent::setUp();
  $data_type = $this
    ->createMock(DataTypeInterface::class);
  $data_type
    ->expects($this
    ->any())
    ->method('getValue')
    ->willReturnCallback(function ($v) {
    return "*{$v}";
  });

  /** @var \Drupal\search_api\DataType\DataTypePluginManager|\PHPUnit\Framework\MockObject\MockObject $data_type_manager */
  $data_type_manager = $this
    ->getMockBuilder('Drupal\\search_api\\DataType\\DataTypePluginManager')
    ->disableOriginalConstructor()
    ->getMock();
  $data_type_manager
    ->expects($this
    ->any())
    ->method('hasDefinition')
    ->willReturn(TRUE);
  $data_type_manager
    ->expects($this
    ->any())
    ->method('createInstance')
    ->willReturn($data_type);
  $index = new Index([], 'search_api_index');
  $this->field = new Field($index, 'field');
  $this->field
    ->setDataTypeManager($data_type_manager);
}