From 00796f61aaa8b862f1a1ae809ca17ef3c154ef8d Mon Sep 17 00:00:00 2001 From: phenaproxima <phenaproxima@205645.no-reply.drupal.org> Date: Wed, 2 Feb 2022 21:16:26 +0000 Subject: [PATCH] Issue #3262016 by phenaproxima: Remove CoreComposerValidator --- automatic_updates.services.yml | 4 -- src/Updater.php | 5 ++ src/Validator/CoreComposerValidator.php | 46 ------------------- .../no_core_requirements/composer.json | 2 +- .../vendor/composer/installed.json | 11 ++++- .../CoreComposerValidatorTest.php | 41 ----------------- 6 files changed, 16 insertions(+), 93 deletions(-) delete mode 100644 src/Validator/CoreComposerValidator.php delete mode 100644 tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php diff --git a/automatic_updates.services.yml b/automatic_updates.services.yml index 27fe9214b0..cbb5b41645 100644 --- a/automatic_updates.services.yml +++ b/automatic_updates.services.yml @@ -82,10 +82,6 @@ services: - '@package_manager.validator.file_system' tags: - { name: event_subscriber } - automatic_updates.validator.core_composer: - class: Drupal\automatic_updates\Validator\CoreComposerValidator - tags: - - { name: event_subscriber } automatic_updates.cron_frequency_validator: class: Drupal\automatic_updates\Validator\CronFrequencyValidator arguments: diff --git a/src/Updater.php b/src/Updater.php index 93aa600370..1f4d879732 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -9,6 +9,11 @@ use Drupal\package_manager\Stage; /** * Defines a service to perform updates. + * + * Currently, only updates to Drupal core are supported. This is done by + * changing the constraint for either 'drupal/core' or 'drupal/core-recommended' + * in the project-level composer.json. If neither package is directly required + * in the project-level composer.json, a requirement will be added. */ class Updater extends Stage { diff --git a/src/Validator/CoreComposerValidator.php b/src/Validator/CoreComposerValidator.php deleted file mode 100644 index 24d3c46a96..0000000000 --- a/src/Validator/CoreComposerValidator.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -namespace Drupal\automatic_updates\Validator; - -use Drupal\automatic_updates\Event\ReadinessCheckEvent; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -/** - * Validates the Drupal core requirements defined in composer.json. - */ -class CoreComposerValidator implements EventSubscriberInterface { - - use StringTranslationTrait; - - /** - * Validates the Drupal core requirements in composer.json. - * - * @param \Drupal\automatic_updates\Event\ReadinessCheckEvent $event - * The event object. - */ - public function checkCoreRequirements(ReadinessCheckEvent $event): void { - // Ensure that either drupal/core or drupal/core-recommended is required. - // If neither is, then core cannot be updated, which we consider an error - // condition. - $core_requirements = array_intersect( - $event->getStage()->getActiveComposer()->getCorePackageNames(), - ['drupal/core', 'drupal/core-recommended'] - ); - if (empty($core_requirements)) { - $event->addError([ - $this->t('Drupal core does not appear to be required in the project-level composer.json.'), - ]); - } - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - return [ - ReadinessCheckEvent::class => ['checkCoreRequirements', 1000], - ]; - } - -} diff --git a/tests/fixtures/project_staged_validation/no_core_requirements/composer.json b/tests/fixtures/project_staged_validation/no_core_requirements/composer.json index 157b54bc9a..43fb9b09eb 100644 --- a/tests/fixtures/project_staged_validation/no_core_requirements/composer.json +++ b/tests/fixtures/project_staged_validation/no_core_requirements/composer.json @@ -9,7 +9,7 @@ "extra": { "_comment": [ "This is an example composer.json that does not require Drupal core.", - "@see \\Drupal\\Tests\\automatic_updates\\Kernel\\ReadinessValidation\\RequirementsValidatorTest" + "@see \\Drupal\\Tests\\automatic_updates\\Kernel\\ReadinessValidation\\CoreComposerValidatorTest" ] } } diff --git a/tests/fixtures/project_staged_validation/no_core_requirements/vendor/composer/installed.json b/tests/fixtures/project_staged_validation/no_core_requirements/vendor/composer/installed.json index aee57674ec..8848abc1a7 100644 --- a/tests/fixtures/project_staged_validation/no_core_requirements/vendor/composer/installed.json +++ b/tests/fixtures/project_staged_validation/no_core_requirements/vendor/composer/installed.json @@ -1,3 +1,12 @@ { - "packages": [] + "packages": [ + { + "name": "drupal/core-recommended", + "version": "9.8.0" + }, + { + "name": "drupal/core", + "version": "9.8.0" + } + ] } diff --git a/tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php b/tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php deleted file mode 100644 index 03930a36b9..0000000000 --- a/tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation; - -use Drupal\package_manager\ValidationResult; -use Drupal\package_manager\PathLocator; -use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; - -/** - * @covers \Drupal\automatic_updates\Validator\CoreComposerValidator - * - * @group automatic_updates - */ -class CoreComposerValidatorTest extends AutomaticUpdatesKernelTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = [ - 'automatic_updates', - 'package_manager', - ]; - - /** - * Tests that an error is raised if core is not required in composer.json. - */ - public function testCoreNotRequired(): void { - // Point to a valid composer.json with no requirements. - $active_dir = __DIR__ . '/../../../fixtures/project_staged_validation/no_core_requirements'; - $locator = $this->prophesize(PathLocator::class); - $locator->getProjectRoot()->willReturn($active_dir); - $locator->getVendorDirectory()->willReturn($active_dir . '/vendor'); - $this->container->set('package_manager.path_locator', $locator->reveal()); - - $error = ValidationResult::createError([ - 'Drupal core does not appear to be required in the project-level composer.json.', - ]); - $this->assertCheckerResultsFromManager([$error], TRUE); - } - -} -- GitLab