function BundleClassTest::testAmbiguousBundleClassExceptionEntityTypeRepository

Checks exception is thrown if two entity types share the same bundle class.

@covers Drupal\Core\Entity\EntityTypeRepository::getEntityTypeFromClass

File

core/tests/Drupal/KernelTests/Core/Entity/BundleClassTest.php, line 240

Class

BundleClassTest
Tests entity bundle classes.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testAmbiguousBundleClassExceptionEntityTypeRepository() : void {
  $this->container
    ->get('state')
    ->set('entity_test_bundle_class_enable_ambiguous_entity_types', TRUE);
  entity_test_create_bundle('entity_test_no_label');
  entity_test_create_bundle('entity_test_no_label', NULL, 'entity_test_no_label');
  // Now that we have an entity bundle class that's shared by two entirely
  // different entity types, we expect an exception to be thrown.
  $this->expectException(AmbiguousBundleClassException::class);
  $entity_type = $this->container
    ->get('entity_type.repository')
    ->getEntityTypeFromClass(EntityTestAmbiguousBundleClass::class);
}

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