ModuleHandlerTest.php

Same filename in this branch
  1. 10 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
  2. 10 core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
Same filename in other branches
  1. 9 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
  2. 9 core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerTest.php
  3. 9 core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
  4. 8.9.x core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
  5. 8.9.x core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerTest.php
  6. 8.9.x core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
  7. 11.x core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
  8. 11.x core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerTest.php
  9. 11.x core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php

Namespace

Drupal\KernelTests\Core\Extension

File

core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\KernelTests\Core\Extension;

use Drupal\Core\Extension\Exception\UnknownExtensionException;
use Drupal\KernelTests\KernelTestBase;

/**
 * @coversDefaultClass \Drupal\Core\Extension\ModuleHandler
 *
 * @group Extension
 */
class ModuleHandlerTest extends KernelTestBase {
    
    /**
     * Tests requesting the name of an invalid module.
     *
     * @covers ::getName
     */
    public function testInvalidGetName() : void {
        $this->expectException(UnknownExtensionException::class);
        $this->expectExceptionMessage('The module module_nonsense does not exist.');
        $module_handler = $this->container
            ->get('module_handler');
        $module_handler->getModule('module_nonsense');
    }
    
    /**
     * Tests deprecation of getName() function.
     *
     * @group legacy
     */
    public function testGetNameDeprecation() : void {
        $this->expectDeprecation('Drupal\\Core\\Extension\\ModuleHandler::getName() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Extension\\ModuleExtensionList::getName($module) instead. See https://www.drupal.org/node/3310017');
        $this->assertNotNull(\Drupal::service('module_handler')->getName('module_test'));
    }

}

Classes

Title Deprecated Summary
ModuleHandlerTest @coversDefaultClass \Drupal\Core\Extension\ModuleHandler

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