function HookOrderTest::setUp

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Hook/HookOrderTest.php, line 26

Class

HookOrderTest
@coversDefaultClass \Drupal\Core\Hook\HookOrder

Namespace

Drupal\Tests\Core\Hook

Code

protected function setUp() : void {
    parent::setUp();
    // "c" first, "b" second, "a" last.
    $this->setUpContainer(TRUE);
    foreach ([
        'a',
        'b',
        'c',
    ] as $key) {
        $this->originalPriorities[$key] = $this->getPriority($key);
    }
    // The documentation does not clarify the order of arguments, let's do so
    // here to make it easier to develop/debug this test.
    $this->assertGreaterThan(1, 2);
    // According to https://symfony.com/doc/current/event_dispatcher.html
    // the higher the number, the earlier a listener is executed. Accordingly
    // assert that "a" is last, "c" is first, "b" is in the middle. The
    // asserts in methods can be compared to these establishing asserts.
    $this->assertGreaterThan($this->getPriority('a'), $this->getPriority('b'));
    $this->assertGreaterThan($this->getPriority('b'), $this->getPriority('c'));
    // This is unnecessary but asserts are free, and it's easier to compare if
    // this is explicit.
    $this->assertGreaterThan($this->getPriority('a'), $this->getPriority('c'));
}

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