class ModuleHandlerDeprecatedHookTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedHookTest.php \Drupal\KernelTests\Core\Extension\ModuleHandlerDeprecatedHookTest
  2. 10 core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedHookTest.php \Drupal\KernelTests\Core\Extension\ModuleHandlerDeprecatedHookTest

Test whether deprecated hook invocations trigger errors.

@group Extension @group legacy

@coversDefaultClass Drupal\Core\Extension\ModuleHandler

Hierarchy

Expanded class hierarchy of ModuleHandlerDeprecatedHookTest

File

core/tests/Drupal/KernelTests/Core/Extension/ModuleHandlerDeprecatedHookTest.php, line 15

Namespace

Drupal\KernelTests\Core\Extension
View source
class ModuleHandlerDeprecatedHookTest extends KernelTestBase {
  protected static $modules = [
    'deprecation_test',
  ];
  
  /**
   * @covers ::invokeDeprecated
   */
  public function testInvokeDeprecated() {
    $this->expectDeprecation('The deprecated hook hook_deprecated_hook() is implemented in these functions: deprecation_test_deprecated_hook(). Use something else.');
    /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
    $module_handler = $this->container
      ->get('module_handler');
    $arg = 'an_arg';
    $this->assertEquals($arg, $module_handler->invokeDeprecated('Use something else.', 'deprecation_test', 'deprecated_hook', [
      $arg,
    ]));
  }
  
  /**
   * @covers ::invokeAllDeprecated
   */
  public function testInvokeAllDeprecated() {
    $this->expectDeprecation('The deprecated hook hook_deprecated_hook() is implemented in these functions: deprecation_test_deprecated_hook(). Use something else.');
    /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
    $module_handler = $this->container
      ->get('module_handler');
    $arg = 'an_arg';
    $this->assertEquals([
      $arg,
    ], $module_handler->invokeAllDeprecated('Use something else.', 'deprecated_hook', [
      $arg,
    ]));
  }
  
  /**
   * @covers ::alterDeprecated
   */
  public function testAlterDeprecated() {
    $this->expectDeprecation('The deprecated alter hook hook_deprecated_alter_alter() is implemented in these functions: deprecation_test_deprecated_alter_alter. Alter something else.');
    /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
    $module_handler = $this->container
      ->get('module_handler');
    $data = [];
    $context1 = 'test1';
    $context2 = 'test2';
    $module_handler->alterDeprecated('Alter something else.', 'deprecated_alter', $data, $context1, $context2);
    $this->assertEquals([
      $context1,
      $context2,
    ], $data);
  }

}

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