function ModuleHandlerTest::getModuleHandler

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

Get a module handler object to test.

Since we have to run these tests in separate processes, we have to use test objects which are serializable. Since ModuleHandler will populate itself with Extension objects, and since Extension objects will try to access DRUPAL_ROOT when they're unserialized, we can't store our mocked ModuleHandler objects as a property in unit tests. They must be generated by the test method by calling this method.

Return value

\Drupal\Core\Extension\ModuleHandler The module handler to test.

13 calls to ModuleHandlerTest::getModuleHandler()
ModuleHandlerTest::testGetHookInfo in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Tests hook_hook_info() fetching through getHookInfo().
ModuleHandlerTest::testGetModuleDirectories in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
@covers ::getModuleDirectories
ModuleHandlerTest::testImplementsHookModuleEnabled in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Tests implementations methods when module is enabled.
ModuleHandlerTest::testInvokeAll in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Tests invoke all.
ModuleHandlerTest::testInvokeModuleEnabled in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Tests invoke methods when module is enabled.

... See full list

File

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

Class

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

Namespace

Drupal\Tests\Core\Extension

Code

protected function getModuleHandler() {
    $module_handler = new ModuleHandler($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);
    return $module_handler;
}

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