function LockFileValidatorTest::testNoStoredHash

Tests exception when a stored hash of the active lock file is unavailable.

@dataProvider providerValidateStageEvents

File

core/modules/package_manager/tests/src/Kernel/LockFileValidatorTest.php, line 150

Class

LockFileValidatorTest
@coversDefaultClass \Drupal\package_manager\Validator\LockFileValidator @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testNoStoredHash(string $event_class) : void {
    $reflector = new \ReflectionClassConstant(LockFileValidator::class, 'KEY');
    $key = $reflector->getValue();
    // Add a listener with an extremely high priority to the same event that
    // should throw an exception. Because the validator uses the default
    // priority of 0, this listener deletes stored hash before the validator
    // runs.
    $this->addEventTestListener(function () use ($key) {
        $this->container
            ->get('keyvalue')
            ->get('package_manager')
            ->delete($key);
    }, $event_class);
    $stage = $this->createStage();
    $stage->create();
    try {
        $stage->require([
            'drupal/core:9.8.1',
        ]);
        $stage->apply();
    } catch (StageException $e) {
        $this->assertSame(\LogicException::class, $e->getPrevious()::class);
        $this->assertSame('Stored hash key deleted.', $e->getMessage());
    }
}

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