function EntityTypeRepositoryTest::testGetEntityTypeFromClassAmbiguousBundleClass

@covers ::getEntityTypeFromClass

File

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

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 testGetEntityTypeFromClassAmbiguousBundleClass() : void {
    $blackcurrant = $this->prophesize(EntityTypeInterface::class);
    $blackcurrant->getOriginalClass()
        ->willReturn(Apple::class);
    $blackcurrant->getClass()
        ->willReturn(Blackcurrant::class);
    $blackcurrant->id()
        ->willReturn('blackcurrant');
    $gala = $this->prophesize(EntityTypeInterface::class);
    $gala->getOriginalClass()
        ->willReturn(Apple::class);
    $gala->getClass()
        ->willReturn(RoyalGala::class);
    $gala->id()
        ->willReturn('gala');
    $this->setUpEntityTypeDefinitions([
        'blackcurrant' => $blackcurrant,
        'gala' => $gala,
    ]);
    $this->entityTypeBundleInfo
        ->getAllBundleInfo()
        ->willReturn([
        'gala' => [
            'royal_gala' => [
                'label' => 'Royal Gala',
                'class' => RoyalGala::class,
            ],
        ],
    ]);
    $this->assertSame('gala', $this->entityTypeRepository
        ->getEntityTypeFromClass(RoyalGala::class));
}

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