You are here

protected function ModuleHandlerTest::getModuleHandler in Drupal 8

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
Test 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
Test implementations methods when module is enabled.
ModuleHandlerTest::testInvokeAll in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Test invoke all.
ModuleHandlerTest::testInvokeModuleEnabled in core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Test 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;
}