function BundleClassTest::testAmbiguousBundleClassExceptionCreate

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/BundleClassTest.php \Drupal\KernelTests\Core\Entity\BundleClassTest::testAmbiguousBundleClassExceptionCreate()
  2. 11.x core/tests/Drupal/KernelTests/Core/Entity/BundleClassTest.php \Drupal\KernelTests\Core\Entity\BundleClassTest::testAmbiguousBundleClassExceptionCreate()

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

@covers Drupal\Core\Entity\ContentEntityStorageBase::create

File

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

Class

BundleClassTest
Tests entity bundle classes.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testAmbiguousBundleClassExceptionCreate() : void {
    $this->container
        ->get('state')
        ->set('entity_test_bundle_class_enable_ambiguous_entity_types', TRUE);
    $this->entityTypeManager
        ->clearCachedDefinitions();
    entity_test_create_bundle('bundle_class');
    entity_test_create_bundle('bundle_class_2');
    // Since we now have two bundles trying to reuse the same class, we expect
    // this to throw an exception.
    $this->expectException(AmbiguousBundleClassException::class);
    EntityTestBundleClass::create();
}

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