function ModuleHandlerTest::testCachedGetImplementationsMissingMethod

Same name 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()

Tests getImplementations.

@covers ::invokeAllWith

File

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

Class

ModuleHandlerTest
@coversDefaultClass \Drupal\Core\Extension\ModuleHandler @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.