function FieldConfigEntityUnitTest::setUp

Same name and namespace in other branches
  1. 8.9.x core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::setUp()
  2. 10 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::setUp()
  3. 11.x core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php, line 76

Class

FieldConfigEntityUnitTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21field%21src%21Entity%21FieldConfig.php/class/FieldConfig/9" title="Defines the Field entity." class="local">\Drupal\field\Entity\FieldConfig</a> @group field

Namespace

Drupal\Tests\field\Unit

Code

protected function setUp() : void {
    $this->entityTypeId = $this->randomMachineName();
    $this->entityType = $this->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityTypeInterface');
    $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $this->entityFieldManager = $this->createMock(EntityFieldManagerInterface::class);
    $this->uuid = $this->createMock('\\Drupal\\Component\\Uuid\\UuidInterface');
    $this->fieldTypePluginManager = $this->createMock('Drupal\\Core\\Field\\FieldTypePluginManagerInterface');
    $container = new ContainerBuilder();
    $container->set('entity_field.manager', $this->entityFieldManager);
    $container->set('entity_type.manager', $this->entityTypeManager);
    $container->set('uuid', $this->uuid);
    $container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
    \Drupal::setContainer($container);
    // Create a mock FieldStorageConfig object.
    $this->fieldStorage = $this->createMock('\\Drupal\\field\\FieldStorageConfigInterface');
    $this->fieldStorage
        ->expects($this->any())
        ->method('getType')
        ->willReturn('test_field');
    $this->fieldStorage
        ->expects($this->any())
        ->method('getName')
        ->willReturn('field_test');
    $this->fieldStorage
        ->expects($this->any())
        ->method('getSettings')
        ->willReturn([]);
    // Place the field in the mocked entity field manager's field registry.
    $this->entityFieldManager
        ->expects($this->any())
        ->method('getFieldStorageDefinitions')
        ->with('test_entity_type')
        ->willReturn([
        $this->fieldStorage
            ->getName() => $this->fieldStorage,
    ]);
}

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