function ComposerProjectTemplatesTest::testMinimumStabilityStrictness

Same name and namespace in other branches
  1. 9 core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php \Drupal\BuildTests\Composer\Template\ComposerProjectTemplatesTest::testMinimumStabilityStrictness()
  2. 10 core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php \Drupal\BuildTests\Composer\Template\ComposerProjectTemplatesTest::testMinimumStabilityStrictness()

Make sure that static::MINIMUM_STABILITY is sufficiently strict.

File

core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php, line 88

Class

ComposerProjectTemplatesTest
Demonstrate that Composer project templates can be built as patched.

Namespace

Drupal\BuildTests\Composer\Template

Code

public function testMinimumStabilityStrictness() : void {
    // Ensure that static::MINIMUM_STABILITY is not less stable than the
    // current core stability. For example, if we've already released a beta on
    // the branch, ensure that we no longer allow alpha dependencies.
    $this->assertGreaterThanOrEqual(array_search($this->getCoreStability(), static::STABILITY_ORDER), array_search(static::MINIMUM_STABILITY, static::STABILITY_ORDER));
    // Ensure that static::MINIMUM_STABILITY is the same as the least stable
    // dependency.
    // - We can't set it stricter than our least stable dependency.
    // - We don't want to set it looser than we need to, because we don't want
    //   to in the future accidentally commit a dependency that regresses our
    //   actual stability requirement without us explicitly changing this
    //   constant.
    $root = $this->getDrupalRoot();
    $process = $this->executeCommand("composer --working-dir={$root} info --format=json");
    $this->assertCommandSuccessful();
    $installed = json_decode($process->getOutput(), TRUE);
    // A lookup of the numerical position of each of the stability terms.
    $stability_order_indexes = array_flip(static::STABILITY_ORDER);
    $minimum_stability_order_index = $stability_order_indexes[static::MINIMUM_STABILITY];
    $exclude = [
        'drupal/core',
        'drupal/core-project-message',
        'drupal/core-vendor-hardening',
    ];
    foreach ($installed['installed'] as $project) {
        // Exclude dependencies that are required with "self.version", since
        // those stabilities will automatically match the corresponding Drupal
        // release.
        if (in_array($project['name'], $exclude, TRUE)) {
            continue;
        }
        // VersionParser::parseStability doesn't play nice with (mostly dev-)
        // versions ending with the first seven characters of the commit ID as
        // returned by "composer info". Let's strip those suffixes here.
        $version = preg_replace('/ [0-9a-f]{7}$/i', '', $project['version']);
        $project_stability = VersionParser::parseStability($version);
        $project_stability_order_index = $stability_order_indexes[$project_stability];
        $project_stabilities[$project['name']] = $project_stability;
        $this->assertGreaterThanOrEqual($minimum_stability_order_index, $project_stability_order_index, sprintf("Dependency %s with stability %s does not meet minimum stability %s.", $project['name'], $project_stability, static::MINIMUM_STABILITY));
    }
    // At least one project should be at the minimum stability.
    $this->assertContains(static::MINIMUM_STABILITY, $project_stabilities);
}

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