diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 1e327d2d7f..e3d620f4c2 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -77,6 +77,18 @@ class Drupal { */ const VERSION = '9.3.0-dev'; + /** + * The latest tagged release on this branch. + * + * When VERSION is not a "-dev" version, this is the same as the VERSION. + * + * When VERSION is a "-dev" version, this is the latest non-dev version that + * is prior to the current state of this codebase. This is useful for knowing + * if the current -dev version is after an alpha, a beta, or an RC, because + * VERSION alone doesn't contain that information. + */ + const VERSION_FLOOR = '9.3.0-dev'; + /** * Core API compatibility. */ diff --git a/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php b/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php index fef7d4775b..26299d8687 100644 --- a/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php +++ b/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php @@ -3,6 +3,7 @@ namespace Drupal\BuildTests\Composer\Template; use Composer\Json\JsonFile; +use Composer\Semver\VersionParser; use Drupal\BuildTests\Framework\BuildTestBase; use Drupal\Composer\Composer; @@ -111,17 +112,6 @@ public function testTemplateCreateProject($project, $package_dir, $docroot_dir) $this->executeCommand("COMPOSER_HOME=$composer_home composer config --no-interaction --global repo.packagist false"); $this->assertCommandSuccessful(); - // Get the Drupal core version branch. For instance, this should be - // 8.9.x-dev for the 8.9.x branch. - $core_version = Composer::drupalVersionBranch(); - - // In order to use create-project on our template, we must have stable - // versions of drupal/core and our other SUT repositories. Since we have - // provided these as path repositories, they will take on the version of - // the root project. We'll make a simulated version number that is stable - // to fulfill this role. - $simulated_stable_version = str_replace('.x-dev', '.99', $core_version); - // Create a "Composer"-type repository containing one entry for every // package in the vendor directory. $vendor_packages_path = $this->getWorkspaceDirectory() . '/vendor_packages/packages.json'; @@ -130,9 +120,12 @@ public function testTemplateCreateProject($project, $package_dir, $docroot_dir) // Make a copy of the code to alter in the workspace directory. $this->copyCodebase(); - // Set the Drupal version and minimum stability of the template projects - Composer::setDrupalVersion($this->getWorkspaceDirectory(), $simulated_stable_version); - $this->assertDrupalVersion($simulated_stable_version, $this->getWorkspaceDirectory()); + // Tests are run on "-dev" versions, but we want to run them as though they + // are run on a release version. Composer::setDrupalVersion() also sets the + // minimum stability based on this version. + $simulated_core_version = \Drupal::VERSION_FLOOR; + Composer::setDrupalVersion($this->getWorkspaceDirectory(), $simulated_core_version); + $this->assertDrupalVersion($simulated_core_version, $this->getWorkspaceDirectory()); // Remove the packages.drupal.org entry (and any other custom repository) // from the SUT's repositories section. There is no way to do this via @@ -154,12 +147,12 @@ public function testTemplateCreateProject($project, $package_dir, $docroot_dir) $this->executeCommand("composer config --no-interaction repositories.$name path $path", $package_dir); $this->assertCommandSuccessful(); } - // Fix up drupal/core-recommended so that it requires a stable version + // Fix up drupal/core-recommended so that it requires a release version // of drupal/core rather than a dev version. $core_recommended_dir = 'composer/Metapackage/CoreRecommended'; $this->executeCommand("composer remove --no-interaction drupal/core --no-update", $core_recommended_dir); $this->assertCommandSuccessful(); - $this->executeCommand("composer require --no-interaction drupal/core:^$simulated_stable_version --no-update", $core_recommended_dir); + $this->executeCommand("composer require --no-interaction drupal/core:^$simulated_core_version --no-update", $core_recommended_dir); $this->assertCommandSuccessful(); // Add our vendor package repository to our SUT's repositories section. @@ -168,32 +161,29 @@ public function testTemplateCreateProject($project, $package_dir, $docroot_dir) $this->assertCommandSuccessful(); $repository_path = $this->getWorkspaceDirectory() . '/test_repository/packages.json'; - $this->makeTestPackage($repository_path, $simulated_stable_version); + $this->makeTestPackage($repository_path, $simulated_core_version); $installed_composer_json = $this->getWorkspaceDirectory() . '/testproject/composer.json'; $autoloader = $this->getWorkspaceDirectory() . '/testproject' . $docroot_dir . '/autoload.php'; $this->assertFileNotExists($autoloader); - // At the moment, we are only testing stable versions. If we used a - // non-stable version instead of $simulated_stable_version, then we would - // also need to pass the --stability flag to composer create-project. - $this->executeCommand("COMPOSER_HOME=$composer_home COMPOSER_ROOT_VERSION=$simulated_stable_version composer create-project --no-ansi $project testproject -vvv --repository $repository_path"); + $this->executeCommand("COMPOSER_HOME=$composer_home COMPOSER_ROOT_VERSION=$simulated_core_version composer create-project --no-ansi $project testproject $simulated_core_version -vvv --repository $repository_path"); $this->assertCommandSuccessful(); // Ensure we used the project from our codebase. - $this->assertErrorOutputContains("Installing $project ($simulated_stable_version): Symlinking from $package_dir"); + $this->assertErrorOutputContains("Installing $project ($simulated_core_version): Symlinking from $package_dir"); // Ensure that we used drupal/core from our codebase. This probably means // that drupal/core-recommended was added successfully by the project. - $this->assertErrorOutputContains("Installing drupal/core ($simulated_stable_version): Symlinking from"); + $this->assertErrorOutputContains("Installing drupal/core ($simulated_core_version): Symlinking from"); // Verify that there is an autoloader. This is written by the scaffold // plugin, so its existence assures us that scaffolding happened. $this->assertFileExists($autoloader); // Verify that the minimum stability in the installed composer.json file - // is 'stable' + // matches the stability of the simulated core version. $this->assertFileExists($installed_composer_json); $composer_json_contents = file_get_contents($installed_composer_json); - $this->assertStringContainsString('"minimum-stability": "stable"', $composer_json_contents); + $this->assertStringContainsString('"minimum-stability": "' . VersionParser::parseStability($simulated_core_version) . '"', $composer_json_contents); // In order to verify that Composer used the path repos for our project, we // have to get the requirements from the project composer.json so we can @@ -215,10 +205,10 @@ public function testTemplateCreateProject($project, $package_dir, $docroot_dir) // we still must check that their installed version matches // COMPOSER_CORE_VERSION. if (array_key_exists($package_name, $metapackage_path_repos)) { - $this->assertErrorOutputContains("Installing $package_name ($simulated_stable_version)"); + $this->assertErrorOutputContains("Installing $package_name ($simulated_core_version)"); } else { - $this->assertErrorOutputContains("Installing $package_name ($simulated_stable_version): Symlinking from"); + $this->assertErrorOutputContains("Installing $package_name ($simulated_core_version): Symlinking from"); } } }