function ModuleHandlerTest::getModuleHandler

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php \Drupal\Tests\Core\Extension\ModuleHandlerTest::getModuleHandler()
  2. 8.9.x core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php \Drupal\Tests\Core\Extension\ModuleHandlerTest::getModuleHandler()
  3. 10 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.

11 calls to ModuleHandlerTest::getModuleHandler()
ModuleHandlerTest::testGetModuleDirectories in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
@covers ::getModuleDirectories
ModuleHandlerTest::testHasImplementations in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Tests hasImplementations.
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 54

Class

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

Namespace

Drupal\Tests\Core\Extension

Code

protected function getModuleHandler($implementations = []) {
    $module_handler = new ModuleHandler($this->root, [], $this->eventDispatcher, $implementations);
    $module_handler->addModule('module_handler_test', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test');
    return $module_handler;
}

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