function FieldDefinitionListenerTest::setUpEntityTypeManager

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::setUpEntityTypeManager()
  2. 10 core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::setUpEntityTypeManager()
  3. 11.x core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::setUpEntityTypeManager()

Sets up the entity type manager to be tested.

Parameters

\Drupal\Core\Entity\EntityTypeInterface[]|\Prophecy\Prophecy\ProphecyInterface[] $definitions: (optional) An array of entity type definitions.

5 calls to FieldDefinitionListenerTest::setUpEntityTypeManager()
FieldDefinitionListenerTest::testOnFieldDefinitionCreateExistingField in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionCreate[[api-linebreak]]
FieldDefinitionListenerTest::testOnFieldDefinitionCreateNewField in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionCreate[[api-linebreak]]
FieldDefinitionListenerTest::testOnFieldDefinitionDeleteMultipleBundles in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionDelete[[api-linebreak]]
FieldDefinitionListenerTest::testOnFieldDefinitionDeleteSingleBundles in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionDelete[[api-linebreak]]
FieldDefinitionListenerTest::testOnFieldDefinitionUpdate in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionUpdate[[api-linebreak]]

File

core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php, line 79

Class

FieldDefinitionListenerTest
@coversDefaultClass \Drupal\Core\Field\FieldDefinitionListener[[api-linebreak]] @group Field

Namespace

Drupal\Tests\Core\Field

Code

protected function setUpEntityTypeManager($definitions = []) {
  foreach ($definitions as $key => $entity_type) {
    // \Drupal\Core\Entity\EntityTypeInterface::getLinkTemplates() is called
    // by \Drupal\Core\Entity\EntityTypeManager::processDefinition() so it must
    // always be mocked.
    $entity_type->getLinkTemplates()
      ->willReturn([]);
    $definitions[$key] = $entity_type->reveal();
  }
  $this->entityTypeManager
    ->getDefinition(Argument::cetera())
    ->will(function ($args) use ($definitions) {
    $entity_type_id = $args[0];
    $exception_on_invalid = $args[1];
    if (isset($definitions[$entity_type_id])) {
      return $definitions[$entity_type_id];
    }
    elseif (!$exception_on_invalid) {
      return NULL;
    }
    else {
      throw new PluginNotFoundException($entity_type_id);
    }
  });
  $this->entityTypeManager
    ->getDefinitions()
    ->willReturn($definitions);
}

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