function ComposerProjectTemplatesTest::getCoreStability

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

Returns the stability of the current core version.

If the current core version is a tagged release (not a "-dev" version), this returns the stability of that version.

If the current core version is a "-dev" version, but not a "x.y.0-dev" version, this returns "stable", because it means that the corresponding "x.y.0" has already been released, and only stable changes are now permitted on the branch.

If the current core version is a "x.y.0-dev" version, then this returns the stability of the latest tag that matches "x.y.0-*". For example, if we've already released "x.y.0-alpha1" but have not yet released "x.y.0-beta1", then the current stability is "alpha". If there aren't any matching tags, this returns "dev", because it means that an "alpha1" has not yet been released.

Return value

string One of: "dev", "alpha", "beta", "RC", "stable".

1 call to ComposerProjectTemplatesTest::getCoreStability()
ComposerProjectTemplatesTest::testMinimumStabilityStrictness in core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
Make sure that static::MINIMUM_STABILITY is sufficiently strict.

File

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

Class

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

Namespace

Drupal\BuildTests\Composer\Template

Code

protected function getCoreStability() {
    $version = \Drupal::VERSION;
    // If the current version is x.y-dev then this is the equivalent of the main
    // branch and should be treated as a dev release.
    if (preg_match('/^(\\d)+\\.(\\d)+-dev$/', $version)) {
        return 'dev';
    }
    $stability = VersionParser::parseStability($version);
    if ($stability === 'dev') {
        // Strip off "-dev";
        $version_towards = substr($version, 0, -4);
        if (!str_ends_with($version_towards, '.0')) {
            // If the current version is developing towards an x.y.z release where
            // z is not 0, it means that the x.y.0 has already been released, and
            // only stable changes are permitted on the branch.
            $stability = 'stable';
        }
        else {
            // If the current version is developing towards an x.y.0 release, there
            // might be tagged pre-releases. "git describe" identifies the latest
            // one.
            $root = $this->getDrupalRoot();
            $process = $this->executeCommand("git -C \"{$root}\" describe --abbrev=0 --match=\"{$version_towards}-*\"");
            // If there aren't any tagged pre-releases for this version yet, return
            // 'dev'. Ensure that any other error from "git describe" causes a test
            // failure.
            if (!$process->isSuccessful()) {
                $this->assertErrorOutputContains('No names found, cannot describe anything.');
                return 'dev';
            }
            // We expect a pre-release, because:
            // - A tag should not be of "dev" stability.
            // - After a "stable" release is made, \Drupal::VERSION is incremented,
            //   so there should not be a stable release on that new version.
            $stability = VersionParser::parseStability(trim($process->getOutput()));
            $this->assertContains($stability, [
                'alpha',
                'beta',
                'RC',
            ]);
        }
    }
    return $stability;
}

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