function HookCollectorPassTest::testOrdering

Test that ordering works.

Attributes

#[IgnoreDeprecations]

File

core/tests/Drupal/KernelTests/Core/Hook/HookCollectorPassTest.php, line 65

Class

HookCollectorPassTest
Tests Drupal\Core\Hook\HookCollectorPass.

Namespace

Drupal\KernelTests\Core\Hook

Code

public function testOrdering() : void {
  $container = new ContainerBuilder();
  $module_filenames = [
    'module_handler_test_all1' => [
      'pathname' => "core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_all1/module_handler_test_all1.info.yml",
    ],
    'module_handler_test_all2' => [
      'pathname' => "core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_all2/module_handler_test_all2.info.yml",
    ],
  ];
  include_once 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_all1/src/Hook/ModuleHandlerTestAll1Hooks.php';
  $container->setParameter('container.modules', $module_filenames);
  $keyvalue = new KeyValueMemoryFactory();
  $container->set('keyvalue', $keyvalue);
  $container->set('cache.bootstrap', new NullBackend('bootstrap'));
  (new HookCollectorPass())->process($container);
  (new HookCollectorKeyValueWritePass())->process($container);
  $this->assertRegisteredHooks([
    'hook' => [
      'module_handler_test_all1_hook' => 'module_handler_test_all1',
      'module_handler_test_all2_hook' => 'module_handler_test_all2',
    ],
    'module_implements_alter' => [
      'module_handler_test_all1_module_implements_alter' => 'module_handler_test_all1',
    ],
    'order1' => [
      'module_handler_test_all2_order1' => 'module_handler_test_all2',
      ModuleHandlerTestAll1Hooks::class . '::order' => 'module_handler_test_all1',
    ],
    'order2' => [
      ModuleHandlerTestAll1Hooks::class . '::order' => 'module_handler_test_all1',
      'module_handler_test_all2_order2' => 'module_handler_test_all2',
    ],
  ], $container);
}

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