function ModuleHandlerTest::testCachedGetImplementations

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

Tests getImplementations.

@covers ::invokeAllWith

File

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

Class

ModuleHandlerTest
@coversDefaultClass \Drupal\Core\Extension\ModuleHandler @runTestsInSeparateProcesses

Namespace

Drupal\Tests\Core\Extension

Code

public function testCachedGetImplementations() {
    $this->cacheBackend
        ->expects($this->exactly(1))
        ->method('get')
        ->will($this->onConsecutiveCalls((object) [
        'data' => [
            'hook' => [
                'module_handler_test' => 'test',
            ],
        ],
    ]));
    // 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',
        'loadInclude',
    ])
        ->getMock();
    $module_handler->load('module_handler_test');
    $module_handler->expects($this->never())
        ->method('buildImplementationInfo');
    $module_handler->expects($this->once())
        ->method('loadInclude');
    $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.