You are here

public function ModuleHandlerTest::testModuleReloading in Drupal 8

Test reload method.

@covers ::reload

File

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

Class

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

Namespace

Drupal\Tests\Core\Extension

Code

public function testModuleReloading() {
  $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,
  ])
    ->setMethods([
    'load',
  ])
    ->getMock();

  // First reload.
  $module_handler
    ->expects($this
    ->at(0))
    ->method('load')
    ->with($this
    ->equalTo('module_handler_test'));

  // Second reload.
  $module_handler
    ->expects($this
    ->at(1))
    ->method('load')
    ->with($this
    ->equalTo('module_handler_test'));
  $module_handler
    ->expects($this
    ->at(2))
    ->method('load')
    ->with($this
    ->equalTo('module_handler_test_added'));
  $module_handler
    ->reload();
  $module_handler
    ->addModule('module_handler_test_added', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added');
  $module_handler
    ->reload();
}