function PackageManagerKernelTestBase::assertEventPropagationStopped

Asserts event propagation is stopped by a certain event subscriber.

Parameters

string $event_class: The event during which propagation is expected to stop.

callable $expected_propagation_stopper: The event subscriber (which subscribes to the given event class) which is expected to stop propagation. This event subscriber must have been registered by one of the installed Drupal module.

3 calls to PackageManagerKernelTestBase::assertEventPropagationStopped()
BaseRequirementsFulfilledValidatorTest::testBaseRequirement in core/modules/package_manager/tests/src/Kernel/BaseRequirementsFulfilledValidatorTest.php
Tests that base requirement failures stop event propagation.
EnvironmentSupportValidatorTest::testInvalidUrl in core/modules/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php
Tests handling of an invalid URL in the environment support variable.
EnvironmentSupportValidatorTest::testInvalidUrlDuringPreApply in core/modules/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php
Tests an invalid URL in the environment support variable during pre-apply.

File

core/modules/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php, line 398

Class

PackageManagerKernelTestBase
Base class for kernel tests of Package Manager's functionality.

Namespace

Drupal\Tests\package_manager\Kernel

Code

protected function assertEventPropagationStopped(string $event_class, callable $expected_propagation_stopper) : void {
    $priority = $this->container
        ->get('event_dispatcher')
        ->getListenerPriority($event_class, $expected_propagation_stopper);
    // Ensure the event subscriber was actually a listener for the event.
    $this->assertIsInt($priority);
    // Add a listener with a priority that is 1 less than priority of the
    // event subscriber. This listener would be called after
    // $expected_propagation_stopper if the event propagation was not stopped
    // and cause the test to fail.
    $this->addEventTestListener(function () use ($event_class) : void {
        $this->fail('Event propagation should have been stopped during ' . $event_class . '.');
    }, $event_class, $priority - 1);
}

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