function EntityTypeRepositoryTest::testGetEntityTypeFromClassNoMatch

Tests get entity type from class no match.

@legacy-covers ::getEntityTypeFromClass

File

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

Class

EntityTypeRepositoryTest
Tests Drupal\Core\Entity\EntityTypeRepository.

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetEntityTypeFromClassNoMatch() : void {
  $apple = $this->prophesize(EntityTypeInterface::class);
  $banana = $this->prophesize(EntityTypeInterface::class);
  $this->setUpEntityTypeDefinitions([
    'apple' => $apple,
    'banana' => $banana,
  ]);
  $apple->getOriginalClass()
    ->willReturn('\\Drupal\\apple\\Entity\\Apple');
  $banana->getOriginalClass()
    ->willReturn('\\Drupal\\banana\\Entity\\Banana');
  $this->expectException(NoCorrespondingEntityClassException::class);
  $this->expectExceptionMessage('The \\Drupal\\pear\\Entity\\Pear class does not correspond to an entity type.');
  $this->entityTypeRepository
    ->getEntityTypeFromClass('\\Drupal\\pear\\Entity\\Pear');
}

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