function ModuleHandlerTest::testHasImplementations
Tests hasImplementations.
@legacy-covers ::hasImplementations
File
-
core/
tests/ Drupal/ Tests/ Core/ Extension/ ModuleHandlerTest.php, line 411
Class
Namespace
Drupal\Tests\Core\ExtensionCode
public function testHasImplementations() : void {
$implementations = [
'some_hook' => [
TestHookClass::class . '::someMethod' => 'some_module',
],
// Set up a hook list closure with empty result.
// This can theoretically happen if the implementations are for modules that
// are not installed.
'empty_hook' => [],
];
$module_handler = $this->getModuleHandler([], $implementations);
$module_handler->setModuleList([
'some_module' => TRUE,
]);
$r = new \ReflectionObject($module_handler);
$get_lists = fn() => $r->getProperty('hookImplementationLists')
->getValue($module_handler);
$this->assertSame([], $get_lists());
$this->assertTrue($module_handler->hasImplementations('some_hook'));
$this->assertEquals([
'some_hook' => new ImplementationList([
TestHookClass::class . '::someMethod',
], [
'some_module',
]),
], $get_lists());
$this->assertFalse($module_handler->hasImplementations('unknown_hook'));
$this->assertEquals([
'some_hook' => new ImplementationList([
TestHookClass::class . '::someMethod',
], [
'some_module',
]),
'unknown_hook' => new ImplementationList([], []),
], $get_lists());
$this->assertFalse($module_handler->hasImplementations('empty_hook'));
$this->assertEquals([
'some_hook' => new ImplementationList([
TestHookClass::class . '::someMethod',
], [
'some_module',
]),
'unknown_hook' => new ImplementationList([], []),
'empty_hook' => new ImplementationList([], []),
], $get_lists());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.