function EntityTypeManagerTest::testGetHandler

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

Tests the getHandler() method.

@covers ::getHandler

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php, line 304

Class

EntityTypeManagerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityTypeManager.php/class/EntityTypeManager/11.x" title="Manages entity type plugin definitions." class="local">\Drupal\Core\Entity\EntityTypeManager</a> @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetHandler() : void {
    $class = get_class($this->getMockForAbstractClass(TestEntityHandlerBase::class));
    $apple = $this->prophesize(EntityTypeInterface::class);
    $apple->getHandlerClass('storage')
        ->willReturn($class);
    $this->setUpEntityTypeDefinitions([
        'apple' => $apple,
    ]);
    $apple_controller = $this->entityTypeManager
        ->getHandler('apple', 'storage');
    $this->assertInstanceOf($class, $apple_controller);
    $this->assertInstanceOf(ModuleHandlerInterface::class, $apple_controller->moduleHandler);
    $this->assertInstanceOf(TranslationInterface::class, $apple_controller->stringTranslation);
}

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