function ImplementationListTest::testPublicMethods
Tests public methods on a common instance.
This is easier than separate test methods.
File
-
core/
tests/ Drupal/ Tests/ Core/ Hook/ ImplementationListTest.php, line 31
Class
- ImplementationListTest
- Tests ImplementationList.
Namespace
Drupal\Tests\Core\HookCode
public function testPublicMethods() : void {
$listeners = [
fn() => 'a0',
fn() => 'b',
fn() => 'a1',
];
$modules = [
'module_a',
'module_b',
// Repeat the same module.
'module_a',
];
$list = new ImplementationList($listeners, $modules);
// Test public properties.
$this->assertSame($listeners, $list->listeners);
$this->assertSame($modules, $list->modules);
// Test iterateByModule().
$i = 0;
foreach ($list->iterateByModule() as $module => $listener) {
$this->assertSame($modules[$i], $module);
$this->assertSame($listeners[$i], $listener);
++$i;
}
// Test getForModule().
$this->assertSame([], $list->getForModule('other_module'));
$this->assertSame([
$listeners[0],
$listeners[2],
], $list->getForModule('module_a'));
$this->assertSame([
$listeners[1],
], $list->getForModule('module_b'));
// Test hasImplementations().
$this->assertTrue($list->hasImplementations());
// Test hasImplementationsForModules().
$this->assertFalse($list->hasImplementationsForModules([
'other_module',
]));
$this->assertFalse($list->hasImplementationsForModules([]));
$this->assertTrue($list->hasImplementationsForModules([
'other_module',
'module_a',
]));
$this->assertTrue($list->hasImplementationsForModules([
'module_b',
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.