Skip to content
Snippets Groups Projects
Commit 2d56faea authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3259656 by phenaproxima: Require Composer 2.2.4 or later

parent 2da91c69
No related branches found
No related tags found
No related merge requests found
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
namespace Drupal\package_manager\Validator; namespace Drupal\package_manager\Validator;
use Composer\Semver\Comparator;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\Core\Extension\ExtensionVersion;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use PhpTuf\ComposerStager\Domain\Process\OutputCallbackInterface; use PhpTuf\ComposerStager\Domain\Process\OutputCallbackInterface;
...@@ -18,6 +18,13 @@ class ComposerExecutableValidator implements PreOperationStageValidatorInterface ...@@ -18,6 +18,13 @@ class ComposerExecutableValidator implements PreOperationStageValidatorInterface
use StringTranslationTrait; use StringTranslationTrait;
/**
* The minimum required version of Composer.
*
* @var string
*/
public const MINIMUM_COMPOSER_VERSION = '2.2.4';
/** /**
* The Composer runner. * The Composer runner.
* *
...@@ -60,13 +67,11 @@ class ComposerExecutableValidator implements PreOperationStageValidatorInterface ...@@ -60,13 +67,11 @@ class ComposerExecutableValidator implements PreOperationStageValidatorInterface
} }
if ($this->version) { if ($this->version) {
$major_version = ExtensionVersion::createFromVersionString($this->version) if (Comparator::lessThan($this->version, static::MINIMUM_COMPOSER_VERSION)) {
->getMajorVersion();
if ($major_version < 2) {
$event->addError([ $event->addError([
$this->t('Composer 2 or later is required, but version @version was detected.', [ $this->t('Composer @minimum_version or later is required, but version @detected_version was detected.', [
'@version' => $this->version, '@minimum_version' => static::MINIMUM_COMPOSER_VERSION,
'@detected_version' => $this->version,
]), ]),
]); ]);
} }
......
...@@ -52,17 +52,22 @@ class ComposerExecutableValidatorTest extends PackageManagerKernelTestBase { ...@@ -52,17 +52,22 @@ class ComposerExecutableValidatorTest extends PackageManagerKernelTestBase {
// in the validation result, so we need a function to churn out those fake // in the validation result, so we need a function to churn out those fake
// results for the test method. // results for the test method.
$unsupported_version = function (string $version): ValidationResult { $unsupported_version = function (string $version): ValidationResult {
$minimum_version = ComposerExecutableValidator::MINIMUM_COMPOSER_VERSION;
return ValidationResult::createError([ return ValidationResult::createError([
"Composer 2 or later is required, but version $version was detected.", "Composer $minimum_version or later is required, but version $version was detected.",
]); ]);
}; };
return [ return [
// A valid 2.x version of Composer should not produce any errors.
[ [
'2.1.6', ComposerExecutableValidator::MINIMUM_COMPOSER_VERSION,
[], [],
], ],
[
'2.1.6',
[$unsupported_version('2.1.6')],
],
[ [
'1.10.22', '1.10.22',
[$unsupported_version('1.10.22')], [$unsupported_version('1.10.22')],
...@@ -73,11 +78,11 @@ class ComposerExecutableValidatorTest extends PackageManagerKernelTestBase { ...@@ -73,11 +78,11 @@ class ComposerExecutableValidatorTest extends PackageManagerKernelTestBase {
], ],
[ [
'2.0.0-alpha3', '2.0.0-alpha3',
[], [$unsupported_version('2.0.0-alpha3')],
], ],
[ [
'2.1.0-RC1', '2.1.0-RC1',
[], [$unsupported_version('2.1.0-RC1')],
], ],
[ [
'1.0.0-RC', '1.0.0-RC',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment