function ModuleHandlerTest::testHasImplementations

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php \Drupal\Tests\Core\Extension\ModuleHandlerTest::testHasImplementations()
  2. 11.x core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php \Drupal\Tests\Core\Extension\ModuleHandlerTest::testHasImplementations()

Tests hasImplementations.

@covers ::hasImplementations

File

core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php, line 333

Class

ModuleHandlerTest
@coversDefaultClass \Drupal\Core\Extension\ModuleHandler[[api-linebreak]] @runTestsInSeparateProcesses

Namespace

Drupal\Tests\Core\Extension

Code

public function testHasImplementations() : void {
  $module_handler = $this->getMockBuilder(ModuleHandler::class)
    ->setConstructorArgs([
    $this->root,
    [],
    $this->cacheBackend,
  ])
    ->onlyMethods([
    'buildImplementationInfo',
  ])
    ->getMock();
  $module_handler->expects($this->exactly(2))
    ->method('buildImplementationInfo')
    ->with('hook')
    ->willReturnOnConsecutiveCalls([], [
    'my_module' => FALSE,
  ]);
  // ModuleHandler::buildImplementationInfo mock returns no implementations.
  $this->assertFalse($module_handler->hasImplementations('hook'));
  // Reset static caches.
  $module_handler->resetImplementations();
  // ModuleHandler::buildImplementationInfo mock returns an implementation.
  $this->assertTrue($module_handler->hasImplementations('hook'));
}

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