function StageEventsTest::testValidationResults

Tests that an exception is thrown if an event has validation results.

@dataProvider providerValidationResults

Parameters

string $event_class: The event class to test.

File

core/modules/package_manager/tests/src/Kernel/StageEventsTest.php, line 139

Class

StageEventsTest
Tests that the stage fires events during its lifecycle.

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testValidationResults(string $event_class) : void {
    $error_messages = [
        $this->t('Burn, baby, burn'),
    ];
    // Set up an event listener which will only flag an error for the event
    // class under test.
    $handler = function (SandboxEvent $event) use ($event_class, $error_messages) : void {
        if (get_class($event) === $event_class) {
            if ($event instanceof SandboxValidationEvent) {
                $event->addError($error_messages);
            }
        }
    };
    $this->addEventTestListener($handler, $event_class);
    $result = ValidationResult::createError($error_messages);
    $this->assertResults([
        $result,
    ], $event_class);
}

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