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

Issue #3262016 by phenaproxima: Remove CoreComposerValidator

parent f569f369
No related branches found
No related tags found
1 merge request!193Issue #3262016: CoreComposerValidator examines installed packages, not requirements
......@@ -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:
......
......@@ -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 {
......
<?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],
];
}
}
......@@ -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"
]
}
}
{
"packages": []
"packages": [
{
"name": "drupal/core-recommended",
"version": "9.8.0"
},
{
"name": "drupal/core",
"version": "9.8.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);
}
}
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