// Install the module_test module.
\Drupal::
service('module_installer'
)->
install(['module_test'
]);
// Assert that the \Drupal::moduleHandler() instance has been replaced.
$this->
assertNotSame(\Drupal::
moduleHandler(),
$module_handler, 'The \Drupal::moduleHandler() instance has been replaced during \Drupal::moduleHandler()->install().'
);
// Assert that module_test.module is now included.
$this->
assertTrue(function_exists('module_test_modules_installed'
),
'The file module_test.module was successfully included.'
);
$this->
assertArrayHasKey('module_test', \Drupal::
moduleHandler()->
getModuleList());
$this->
assertTrue(\Drupal::
moduleHandler()->
hasImplementations('modules_installed', 'module_test'
),
'module_test implements hook_modules_installed().'
);
$this->
assertTrue(\Drupal::
moduleHandler()->
hasImplementations('module_implements_alter', 'module_test'
),
'module_test implements hook_module_implements_alter().'
);
// Assert that module_test.implementations.inc is not included yet.
$this->
assertFalse(function_exists('module_test_altered_test_hook'
),
'The file module_test.implementations.inc is not included yet.'
);