function BaseFieldDefinitionTest::setUp

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest::setUp()
  2. 10 core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php \Drupal\Tests\Core\Entity\BaseFieldDefinitionTest::setUp()
  3. 11.x 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')
        ->willReturn([
        $this->fieldType => $this->fieldTypeDefinition,
    ]);
    $field_type_manager->expects($this->any())
        ->method('getDefinition')
        ->with($this->fieldType)
        ->willReturn($this->fieldTypeDefinition);
    $field_type_manager->expects($this->any())
        ->method('getDefaultStorageSettings')
        ->with($this->fieldType)
        ->willReturn($this->fieldTypeDefinition['storage_settings']);
    $field_type_manager->expects($this->any())
        ->method('getDefaultFieldSettings')
        ->with($this->fieldType)
        ->willReturn($this->fieldTypeDefinition['field_settings']);
    $container = new ContainerBuilder();
    $container->set('plugin.manager.field.field_type', $field_type_manager);
    \Drupal::setContainer($container);
}

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