function ModuleHandlerTest::testCachedGetImplementationsMissingMethod

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

Tests getImplementations.

@covers ::invokeAllWith

File

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

Class

ModuleHandlerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Extension%21ModuleHandler.php/class/ModuleHandler/11.x" title="Class that manages modules in a Drupal installation." class="local">\Drupal\Core\Extension\ModuleHandler</a> @runTestsInSeparateProcesses

Namespace

Drupal\Tests\Core\Extension

Code

public function testCachedGetImplementationsMissingMethod() : void {
    $this->cacheBackend
        ->expects($this->exactly(1))
        ->method('get')
        ->willReturn((object) [
        'data' => [
            'hook' => [
                'module_handler_test' => [],
                'module_handler_test_missing' => [],
            ],
        ],
    ]);
    // Ensure buildImplementationInfo doesn't get called and that we work off cached results.
    $module_handler = $this->getMockBuilder(ModuleHandler::class)
        ->setConstructorArgs([
        $this->root,
        [
            'module_handler_test' => [
                'type' => 'module',
                'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml',
                'filename' => 'module_handler_test.module',
            ],
        ],
        $this->cacheBackend,
    ])
        ->onlyMethods([
        'buildImplementationInfo',
    ])
        ->getMock();
    $module_handler->load('module_handler_test');
    $module_handler->expects($this->never())
        ->method('buildImplementationInfo');
    $implementors = [];
    $module_handler->invokeAllWith('hook', function (callable $hook, string $module) use (&$implementors) {
        $implementors[] = $module;
    });
    $this->assertEquals([
        'module_handler_test',
    ], $implementors);
}

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