function KernelTestHooksTest::testHookMethodExecution
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Hook/KernelTestHooksTest.php \Drupal\KernelTests\Core\Hook\KernelTestHooksTest::testHookMethodExecution()
Invoke hooks and alter hooks and confirm implementations are executed.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Hook/ KernelTestHooksTest.php, line 22
Class
- KernelTestHooksTest
- Tests that hook implementations in Kernel test classes are executed.
Namespace
Drupal\KernelTests\Core\HookCode
public function testHookMethodExecution() : void {
// Invoke a hook and confirm hookTestHook() executed.
$values = \Drupal::moduleHandler()->invokeAll('test_hook');
$this->assertSame([
static::class . '::hookTestHook',
], $values);
// Invoke alter hooks, with multiple types of related hooks and confirm that
// both hookTestHookAlter() and hookTestVariantHookAlter() executed.
$alterHooks = [
'test_hook',
'test_variant_hook',
];
\Drupal::moduleHandler()->alter($alterHooks, $values);
$this->assertSame([
static::class . '::hookTestHook',
static::class . '::hookTestHookAlter',
static::class . '::hookTestVariantHookAlter',
], $values);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.