function ModuleHandlerTest::testSetModuleList

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php \Drupal\Tests\Core\Extension\ModuleHandlerTest::testSetModuleList()
  2. 10 core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php \Drupal\Tests\Core\Extension\ModuleHandlerTest::testSetModuleList()
  3. 11.x core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php \Drupal\Tests\Core\Extension\ModuleHandlerTest::testSetModuleList()

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 175

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,
    ])
        ->onlyMethods([
        '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());
}

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