class HookOrderEqualPriorityTest

@coversDefaultClass \Drupal\Core\Hook\HookOrder

@group Hook

Hierarchy

Expanded class hierarchy of HookOrderEqualPriorityTest

File

core/tests/Drupal/Tests/Core/Hook/HookOrderEqualPriorityTest.php, line 14

Namespace

Drupal\Tests\Core\Hook
View source
class HookOrderEqualPriorityTest extends HookOrderTestBase {
    protected function setUp() : void {
        parent::setUp();
        // The priority of "a", "b", "c" are the same, the order is undefined.
        $this->setUpContainer(FALSE);
        $this->assertSame($this->getPriority('a'), $this->getPriority('b'));
        $this->assertSame($this->getPriority('b'), $this->getPriority('c'));
    }
    
    /**
     * @covers ::first
     */
    public function testFirst() : void {
        // "c" was first, make "a" the first.
        HookOrder::first($this->container, 'test', 'a::a');
        $this->assertGreaterThan($this->getPriority('c'), $this->getPriority('a'));
        $this->assertGreaterThan($this->getPriority('b'), $this->getPriority('a'));
        // Nothing else can be asserted: by setting the same priority, the setup
        // had undefined order and so the services not included in the helper call
        // can be in any order.
    }
    
    /**
     * @covers ::last
     */
    public function testLast() : void {
        // "c" was first, make it the last.
        HookOrder::last($this->container, 'test', 'c::c');
        $this->assertGreaterThan($this->getPriority('c'), $this->getPriority('a'));
        $this->assertGreaterThan($this->getPriority('c'), $this->getPriority('b'));
        // Nothing else can be asserted: by setting the same priority, the setup
        // had undefined order and so the services not included in the helper call
        // can be in any order.
    }
    
    /**
     * @covers ::before
     */
    public function testBefore() : void {
        // "a" was last, move it before "b".
        HookOrder::before($this->container, 'test', 'a::a', 'b::b');
        $this->assertGreaterThan($this->getPriority('b'), $this->getPriority('a'));
        // Nothing else can be asserted: by setting the same priority, the setup
        // had undefined order and so the services not included in the helper call
        // can be in any order.
    }
    
    /**
     * @covers ::after
     */
    public function testAfter() : void {
        // "c" was first, move it after "b".
        HookOrder::after($this->container, 'test', 'c::c', 'b::b');
        $this->assertGreaterThan($this->getPriority('c'), $this->getPriority('b'));
        // Nothing else can be asserted: by setting the same priority, the setup
        // had undefined order and so the services not included in the helper call
        // can be in any order.
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
HookOrderEqualPriorityTest::setUp protected function Overrides UnitTestCase::setUp
HookOrderEqualPriorityTest::testAfter public function @covers ::after
HookOrderEqualPriorityTest::testBefore public function @covers ::before
HookOrderEqualPriorityTest::testFirst public function @covers ::first
HookOrderEqualPriorityTest::testLast public function @covers ::last
HookOrderTestBase::$container protected property The container builder.
HookOrderTestBase::getPriority protected function Get the priority for a service. 1
HookOrderTestBase::setUpContainer protected function Set up three service listeners, "a", "b" and "c".
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function

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