You are here

protected function BaseFieldDefinitionTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest::setUp()
  2. 9 core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php, line 37

Class

BaseFieldDefinitionTest
Unit test for BaseFieldDefinition.

Namespace

Drupal\Tests\Core\Entity

Code

protected function setUp() : void {

  // Mock the field type manager and place it in the container.
  $field_type_manager = $this
    ->createMock('Drupal\\Core\\Field\\FieldTypePluginManagerInterface');
  $this->fieldType = $this
    ->randomMachineName();
  $this->fieldTypeDefinition = [
    'id' => $this->fieldType,
    'storage_settings' => [
      'some_setting' => 'value 1',
    ],
    'field_settings' => [
      'some_instance_setting' => 'value 2',
    ],
  ];
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->will($this
    ->returnValue([
    $this->fieldType => $this->fieldTypeDefinition,
  ]));
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with($this->fieldType)
    ->will($this
    ->returnValue($this->fieldTypeDefinition));
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefaultStorageSettings')
    ->with($this->fieldType)
    ->will($this
    ->returnValue($this->fieldTypeDefinition['storage_settings']));
  $field_type_manager
    ->expects($this
    ->any())
    ->method('getDefaultFieldSettings')
    ->with($this->fieldType)
    ->will($this
    ->returnValue($this->fieldTypeDefinition['field_settings']));
  $container = new ContainerBuilder();
  $container
    ->set('plugin.manager.field.field_type', $field_type_manager);
  \Drupal::setContainer($container);
}