function ConfigEntityValidationTestBase::loadEntityUnderTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::loadEntityUnderTest()

Loads the entity the test methods of this class validate.

Return value

\Drupal\Core\Config\Entity\ConfigEntityInterface The entity built by ::setUpEnvironment().

File

core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php, line 145

Class

ConfigEntityValidationTestBase
Base class for testing validation of config entities.

Namespace

Drupal\KernelTests\Core\Config

Code

protected function loadEntityUnderTest() : ConfigEntityInterface {
  $recorded = \Drupal::keyValue(static::class)->get(self::ENTITY_UNDER_TEST);
  if ($recorded === NULL) {
    throw new \LogicException(sprintf('%s did not assign ::$entity while building the shared environment. Assign it in ::setUpEnvironment().', static::class));
  }
  [$entity_type_id, $entity_id] = $recorded;
  $entity = \Drupal::entityTypeManager()->getStorage($entity_type_id)
    ->load($entity_id);
  if (!$entity instanceof ConfigEntityInterface) {
    throw new \LogicException(sprintf("The %s '%s' built by %s::setUpEnvironment() no longer exists. A test method must not delete the entity it shares with the other test methods.", $entity_type_id, $entity_id, static::class));
  }
  return $entity;
}

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