function EntityTypeRepositoryTest::testGetEntityTypeFromClassAmbiguousBundleClass

Tests get entity type from class ambiguous bundle class.

@legacy-covers ::getEntityTypeFromClass

File

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

Class

EntityTypeRepositoryTest
Tests Drupal\Core\Entity\EntityTypeRepository.

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.