function ComposerMinimumStabilityValidatorTest::testPreRequireEvent

Tests error if requested version is less stable than the minimum: stable.

File

core/modules/package_manager/tests/src/Kernel/ComposerMinimumStabilityValidatorTest.php, line 20

Class

ComposerMinimumStabilityValidatorTest
@covers \Drupal\package_manager\Validator\ComposerMinimumStabilityValidator @group package_manager @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testPreRequireEvent() : void {
    $stage = $this->createStage();
    $stage->create();
    $result = ValidationResult::createError([
        t("<code>drupal/core</code>'s requested version 9.8.1-beta1 is less stable (beta) than the minimum stability (stable) required in <PROJECT_ROOT>/composer.json."),
    ]);
    try {
        $stage->require([
            'drupal/core:9.8.1-beta1',
        ]);
        $this->fail('Able to require a package even though it did not meet minimum stability.');
    } catch (StageEventException $exception) {
        $this->assertValidationResultsEqual([
            $result,
        ], $exception->event
            ->getResults());
    }
    $stage->destroy();
    // Specifying a stability flag bypasses this check.
    $stage->create();
    $stage->require([
        'drupal/core:9.8.1-beta1@dev',
    ]);
    $stage->destroy();
    // Dev packages are also checked.
    $stage->create();
    $result = ValidationResult::createError([
        t("<code>drupal/core-dev</code>'s requested version 9.8.x-dev is less stable (dev) than the minimum stability (stable) required in <PROJECT_ROOT>/composer.json."),
    ]);
    try {
        $stage->require([], [
            'drupal/core-dev:9.8.x-dev',
        ]);
        $this->fail('Able to require a package even though it did not meet minimum stability.');
    } catch (StageEventException $exception) {
        $this->assertValidationResultsEqual([
            $result,
        ], $exception->event
            ->getResults());
    }
}

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