function HookCollectorPassTest::testCollectsOnlyRootProceduralAndHookDirectoryFiles
File
-
core/
tests/ Drupal/ Tests/ Core/ Hook/ HookCollectorPassTest.php, line 71
Class
Namespace
Drupal\Tests\Core\HookCode
public function testCollectsOnlyRootProceduralAndHookDirectoryFiles() : void {
vfsStream::setup('drupal_root');
vfsStream::create([
'test_module' => [
'test_module.module' => '',
'test_module.install' => '',
'test_module.profile' => '',
'another_module.module' => '',
'ignored.php' => '',
'src' => [
'Hook' => [
'TestHooks.php' => '',
'Subdirectory' => [
'NestedHooks.php' => '',
],
],
'Other' => [
'IgnoredHooks.php' => '',
],
],
'ignored_directory' => [
'ignored.module' => '',
],
],
]);
$collector = new HookCollectorPass();
$get_files = \Closure::bind(static function (HookCollectorPass $collector, string $directory, string $module) : array {
$procedural_files = [
"{$module}.module",
"{$module}.profile",
"{$module}.install",
];
return iterator_to_array($collector->getHookFileIterator($directory, $procedural_files));
}, NULL, HookCollectorBase::class);
$files = $get_files($collector, 'vfs://drupal_root/test_module', 'test_module');
$paths = array_map(static fn(\SplFileInfo $file): string => $file->getPathname(), $files);
sort($paths);
$this->assertSame([
'vfs://drupal_root/test_module/src/Hook/Subdirectory/NestedHooks.php',
'vfs://drupal_root/test_module/src/Hook/TestHooks.php',
'vfs://drupal_root/test_module/test_module.install',
'vfs://drupal_root/test_module/test_module.module',
'vfs://drupal_root/test_module/test_module.profile',
], $paths);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.