You are here

public function ModuleHandlerTest::testSetModuleList in Drupal 8

Ensure setting the module list replaces the module list and resets internal structures.

@covers ::setModuleList

File

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

Class

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

Namespace

Drupal\Tests\Core\Extension

Code

public function testSetModuleList() {
  $fixture_module_handler = $this
    ->getModuleHandler();
  $module_handler = $this
    ->getMockBuilder(ModuleHandler::class)
    ->setConstructorArgs([
    $this->root,
    [],
    $this->cacheBackend,
  ])
    ->setMethods([
    'resetImplementations',
  ])
    ->getMock();

  // Ensure we reset implementations when settings a new modules list.
  $module_handler
    ->expects($this
    ->once())
    ->method('resetImplementations');

  // Make sure we're starting empty.
  $this
    ->assertEquals($module_handler
    ->getModuleList(), []);

  // Replace the list with a prebuilt list.
  $module_handler
    ->setModuleList($fixture_module_handler
    ->getModuleList());

  // Ensure those changes are stored.
  $this
    ->assertEquals($fixture_module_handler
    ->getModuleList(), $module_handler
    ->getModuleList());
}