function FieldConfigEntityUnitTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldConfigEntityUnitTest::setUp()
  2. 8.9.x 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 73

Class

FieldConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldConfig[[api-linebreak]] @group field

Namespace

Drupal\Tests\field\Unit

Code

protected function setUp() : void {
  parent::setUp();
  $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.