function EntityTypeRepositoryTest::testGetEntityTypeFromClassAmbiguous

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php \Drupal\Tests\Core\Entity\EntityTypeRepositoryTest::testGetEntityTypeFromClassAmbiguous()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php \Drupal\Tests\Core\Entity\EntityTypeRepositoryTest::testGetEntityTypeFromClassAmbiguous()
  3. 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php \Drupal\Tests\Core\Entity\EntityTypeRepositoryTest::testGetEntityTypeFromClassAmbiguous()

@covers ::getEntityTypeFromClass

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php, line 170

Class

EntityTypeRepositoryTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityTypeRepository.php/class/EntityTypeRepository/11.x" title="Provides helper methods for loading entity types." class="local">\Drupal\Core\Entity\EntityTypeRepository</a> @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetEntityTypeFromClassAmbiguous() : void {
    $jazz = $this->prophesize(EntityTypeInterface::class);
    $jazz->getOriginalClass()
        ->willReturn('\\Drupal\\apple\\Entity\\Apple');
    $jazz->id()
        ->willReturn('jazz');
    $gala = $this->prophesize(EntityTypeInterface::class);
    $gala->getOriginalClass()
        ->willReturn('\\Drupal\\apple\\Entity\\Apple');
    $gala->id()
        ->willReturn('gala');
    $this->setUpEntityTypeDefinitions([
        'jazz' => $jazz,
        'gala' => $gala,
    ]);
    $this->expectException(AmbiguousEntityClassException::class);
    $this->expectExceptionMessage('Multiple entity types found for \\Drupal\\apple\\Entity\\Apple.');
    $this->entityTypeRepository
        ->getEntityTypeFromClass('\\Drupal\\apple\\Entity\\Apple');
}

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