diff --git a/automatic_updates.services.yml b/automatic_updates.services.yml index 00eb7f862ec05d69e91c090dca73e04e998a642a..83501bfb06b17f9f7b56cf58b669cf1ed50706c6 100644 --- a/automatic_updates.services.yml +++ b/automatic_updates.services.yml @@ -61,66 +61,6 @@ services: class: Drupal\automatic_updates\ReleaseChooser arguments: - '@automatic_updates.validator.version_policy' - automatic_updates.composer_executable_validator: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.composer_executable' - tags: - - { name: event_subscriber } - automatic_updates.settings_validator: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.settings' - tags: - - { name: event_subscriber } - automatic_updates.validator.environment_support: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.environment_support' - tags: - - { name: event_subscriber } - automatic_updates.validator.composer_settings: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.composer_settings' - tags: - - { name: event_subscriber } - automatic_updates.disk_space_validator: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.disk_space' - tags: - - { name: event_subscriber } - automatic_updates.pending_updates_validator: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.pending_updates' - tags: - - { name: event_subscriber } - automatic_updates.validator.file_system_permissions: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.file_system' - tags: - - { name: event_subscriber } - automatic_updates.validator.multisite: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.multisite' - tags: - - { name: event_subscriber } - automatic_updates.validator.symlink: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.symlink' - tags: - - { name: event_subscriber } - automatic_updates.validator.patches: - class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - arguments: - - '@package_manager.validator.patches' - tags: - - { name: event_subscriber } automatic_updates.cron_frequency_validator: class: Drupal\automatic_updates\Validator\CronFrequencyValidator arguments: diff --git a/automatic_updates_extensions/src/Form/UpdateReady.php b/automatic_updates_extensions/src/Form/UpdateReady.php index e3dd0275923225ab3d2eb4e8e6f57437b617f28b..b1c84f5b432a8d0002bb3fc42e51db3aef0530dc 100644 --- a/automatic_updates_extensions/src/Form/UpdateReady.php +++ b/automatic_updates_extensions/src/Form/UpdateReady.php @@ -3,7 +3,6 @@ namespace Drupal\automatic_updates_extensions\Form; use Drupal\automatic_updates\Form\UpdateFormBase; -use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\Exception\ApplyFailedException; use Drupal\package_manager\ProjectInfo; use Drupal\package_manager\ValidationResult; @@ -166,10 +165,7 @@ final class UpdateReady extends UpdateFormBase { // Don't run the status checks once the form has been submitted. if (!$form_state->getUserInput()) { - $event = new StatusCheckEvent($this->updater); - $this->eventDispatcher->dispatch($event); - /** @var \Drupal\package_manager\ValidationResult[] $results */ - $results = $event->getResults(); + $results = $this->runStatusCheck($this->updater, $this->eventDispatcher); // This will have no effect if $results is empty. $this->displayResults($results, $this->renderer); // If any errors occurred, return the form early so the user cannot diff --git a/automatic_updates_extensions/src/Form/UpdaterForm.php b/automatic_updates_extensions/src/Form/UpdaterForm.php index 663b946641f9ff0dac9f3eafd388996d05a4ebd6..03bcba5791c7913c7c29bf2cf33fa3b64086bfd9 100644 --- a/automatic_updates_extensions/src/Form/UpdaterForm.php +++ b/automatic_updates_extensions/src/Form/UpdaterForm.php @@ -2,7 +2,6 @@ namespace Drupal\automatic_updates_extensions\Form; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Form\UpdateFormBase; use Drupal\automatic_updates_extensions\BatchProcessor; use Drupal\automatic_updates_extensions\ExtensionUpdater; @@ -163,9 +162,7 @@ final class UpdaterForm extends UpdateFormBase { $results = []; } else { - $event = new ReadinessCheckEvent($this->extensionUpdater); - $this->eventDispatcher->dispatch($event); - $results = $event->getResults(); + $results = $this->runStatusCheck($this->extensionUpdater, $this->eventDispatcher, TRUE); } $this->displayResults($results, $this->renderer); $security_level = ValidationResult::getOverallSeverity($results); diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php index 06f0a89ba5fb0002ece88954895bf1d0e4c41953..c65ba293a59c587a3779f07da1ebd9973bbf75a5 100644 --- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php +++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\automatic_updates_extensions\Functional; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\package_manager_test_validation\StagedDatabaseUpdateValidator; use Drupal\package_manager\Event\PreApplyEvent; @@ -432,7 +431,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->assertUpdatesCount(1); $message = t("You've not experienced Shakespeare until you have read him in the original Klingon."); $error = ValidationResult::createError([$message]); - TestSubscriber1::setTestResult([$error], ReadinessCheckEvent::class); + TestSubscriber1::setTestResult([$error], StatusCheckEvent::class); $this->getSession()->reload(); $assert->pageTextContains($message); $assert->pageTextContains(static::$errorsExplanation); @@ -450,7 +449,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->checkForUpdates(); $message = t("Warning! Updating this module may cause an error."); $warning = ValidationResult::createWarning([$message]); - TestSubscriber1::setTestResult([$warning], ReadinessCheckEvent::class); + TestSubscriber1::setTestResult([$warning], StatusCheckEvent::class); // Navigate to the automatic updates form. $this->drupalGet('/admin/reports/updates'); $this->clickLink('Update Extensions'); diff --git a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php index d9d52e72d0ef15ee1d93be9fffe1a17aea559580..08a7a6f5f2b3feaa2d1c454d968eb3f345213e3f 100644 --- a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php +++ b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php @@ -3,11 +3,11 @@ namespace Drupal\Tests\automatic_updates_extensions\Kernel; use Drupal\automatic_updates\Exception\UpdateException; +use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreRequireEvent; use Drupal\package_manager\ValidationResult; -use Drupal\package_manager_test_validation\EventSubscriber\TestSubscriber; use Drupal\Tests\user\Traits\UserCreationTrait; /** @@ -165,7 +165,7 @@ class ExtensionUpdaterTest extends AutomaticUpdatesExtensionsKernelTestBase { $results = [ ValidationResult::createError(['An error of some sorts.']), ]; - TestSubscriber::setTestResult($results, $event_class); + TestSubscriber1::setTestResult($results, $event_class); try { $extension_updater->begin(['my_module' => '9.8.1']); $extension_updater->stage(); diff --git a/package_manager/src/StatusCheckTrait.php b/package_manager/src/StatusCheckTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..25a315ee4f503701ca9adfeadd4bce6ebfd01fbb --- /dev/null +++ b/package_manager/src/StatusCheckTrait.php @@ -0,0 +1,49 @@ +<?php + +namespace Drupal\package_manager; + +use Drupal\automatic_updates\Event\ReadinessCheckEvent; +use Drupal\package_manager\Event\StatusCheckEvent; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + +/** + * Contains helper methods to run status checks on a stage. + * + * @internal + * This is an internal part of Package Manager and may be changed or removed + * at any time without warning. External code should not use or interact with + * this trait. + */ +trait StatusCheckTrait { + + /** + * Runs a status check for a stage and returns the results, if any. + * + * @param \Drupal\package_manager\Stage $stage + * The stage to run the status check for. + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher + * (optional) The event dispatcher service. + * @param bool $do_readiness_check + * (optional) Whether to also run readiness checks for the stage + * (deprecated). Defaults to FALSE. + * + * @return \Drupal\package_manager\ValidationResult[] + * The results of the status check. If a readiness check was also done, + * its results will be included. + */ + protected function runStatusCheck(Stage $stage, EventDispatcherInterface $event_dispatcher = NULL, bool $do_readiness_check = FALSE): array { + $event_dispatcher ??= \Drupal::service('event_dispatcher'); + + $event = new StatusCheckEvent($stage); + $event_dispatcher->dispatch($event); + $results = $event->getResults(); + + if ($do_readiness_check && class_exists(ReadinessCheckEvent::class) && $event_dispatcher->hasListeners(ReadinessCheckEvent::class)) { + $event = new ReadinessCheckEvent($stage); + $event_dispatcher->dispatch($event); + $results = array_merge($results, $event->getResults()); + } + return $results; + } + +} diff --git a/package_manager/src/Validator/ComposerExecutableValidator.php b/package_manager/src/Validator/ComposerExecutableValidator.php index 9fa5315ae8ef99ce500c6cf86b85e4baa7bbf80c..8e99ac8789121e941c301faf243579749d145959 100644 --- a/package_manager/src/Validator/ComposerExecutableValidator.php +++ b/package_manager/src/Validator/ComposerExecutableValidator.php @@ -13,6 +13,7 @@ use Drupal\package_manager\Event\StatusCheckEvent; use PhpTuf\ComposerStager\Domain\Exception\ExceptionInterface; use PhpTuf\ComposerStager\Domain\Service\ProcessOutputCallback\ProcessOutputCallbackInterface; use PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Validates the Composer executable is the correct version. @@ -22,7 +23,7 @@ use PhpTuf\ComposerStager\Domain\Service\ProcessRunner\ComposerRunnerInterface; * at any time without warning. External code should not interact with this * class. */ -final class ComposerExecutableValidator implements PreOperationStageValidatorInterface, ProcessOutputCallbackInterface { +final class ComposerExecutableValidator implements EventSubscriberInterface, ProcessOutputCallbackInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/ComposerPatchesValidator.php b/package_manager/src/Validator/ComposerPatchesValidator.php index f25296edb093c5634b25cb65740c16a9224ab614..9a930e06ad0c3301165b9f72b667e5baa3b97b3b 100644 --- a/package_manager/src/Validator/ComposerPatchesValidator.php +++ b/package_manager/src/Validator/ComposerPatchesValidator.php @@ -6,11 +6,12 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\StatusCheckEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Validates the configuration of the cweagans/composer-patches plugin. */ -class ComposerPatchesValidator implements PreOperationStageValidatorInterface { +class ComposerPatchesValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/ComposerSettingsValidator.php b/package_manager/src/Validator/ComposerSettingsValidator.php index 0e35167e738382f80202fc4fe6629ecc020d78c0..c80aecbd07f3b86eb5b415b88f57d1acae1edccb 100644 --- a/package_manager/src/Validator/ComposerSettingsValidator.php +++ b/package_manager/src/Validator/ComposerSettingsValidator.php @@ -7,6 +7,7 @@ use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\StatusCheckEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Validates certain Composer settings. @@ -16,7 +17,7 @@ use Drupal\package_manager\Event\StatusCheckEvent; * at any time without warning. External code should not interact with this * class. */ -final class ComposerSettingsValidator implements PreOperationStageValidatorInterface { +final class ComposerSettingsValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/DiskSpaceValidator.php b/package_manager/src/Validator/DiskSpaceValidator.php index 59dc1ade35e20c51ad0b395d11046b4cee6e127a..7c8e4842cc8d44524521762df01befbce5306f82 100644 --- a/package_manager/src/Validator/DiskSpaceValidator.php +++ b/package_manager/src/Validator/DiskSpaceValidator.php @@ -10,6 +10,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\PathLocator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Validates that there is enough free disk space to do staging operations. @@ -19,7 +20,7 @@ use Drupal\package_manager\PathLocator; * at any time without warning. External code should not interact with this * class. */ -class DiskSpaceValidator implements PreOperationStageValidatorInterface { +class DiskSpaceValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/EnvironmentSupportValidator.php b/package_manager/src/Validator/EnvironmentSupportValidator.php index 76679ba87fda53aeb021bc52922322814860a580..8e124b9b3e9be375ec1cbf8b90e72735e34e5008 100644 --- a/package_manager/src/Validator/EnvironmentSupportValidator.php +++ b/package_manager/src/Validator/EnvironmentSupportValidator.php @@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\Core\Url; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Checks that the environment has support for Package Manager. @@ -17,7 +18,7 @@ use Drupal\Core\Url; * at any time without warning. External code should not interact with this * class. */ -final class EnvironmentSupportValidator implements PreOperationStageValidatorInterface { +final class EnvironmentSupportValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/LockFileValidator.php b/package_manager/src/Validator/LockFileValidator.php index 6f2f7facdc426d89acf4a613d725dccc20fa050e..c95eb763200bf638d7ea7e251c6106cd5f1032fc 100644 --- a/package_manager/src/Validator/LockFileValidator.php +++ b/package_manager/src/Validator/LockFileValidator.php @@ -12,6 +12,7 @@ use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\PreRequireEvent; use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\PathLocator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Checks that the active lock file is unchanged during stage operations. @@ -21,7 +22,7 @@ use Drupal\package_manager\PathLocator; * at any time without warning. External code should not interact with this * class. */ -final class LockFileValidator implements PreOperationStageValidatorInterface { +final class LockFileValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/MultisiteValidator.php b/package_manager/src/Validator/MultisiteValidator.php index bd9c5a4b1af3af762d40a5015b97f3ae45e944b6..c8f3b0ed6fe7ff92d7c51181b2c30b345b3810d1 100644 --- a/package_manager/src/Validator/MultisiteValidator.php +++ b/package_manager/src/Validator/MultisiteValidator.php @@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\PathLocator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Checks that the current site is not part of a multisite. @@ -17,7 +18,7 @@ use Drupal\package_manager\PathLocator; * at any time without warning. External code should not interact with this * class. */ -final class MultisiteValidator implements PreOperationStageValidatorInterface { +final class MultisiteValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/OverwriteExistingPackagesValidator.php b/package_manager/src/Validator/OverwriteExistingPackagesValidator.php index eddb465f6ec7bcf32734b1237244fc7f538c7ab3..eec6993f313a6b36f058f5ea67fe95c35be5f87b 100644 --- a/package_manager/src/Validator/OverwriteExistingPackagesValidator.php +++ b/package_manager/src/Validator/OverwriteExistingPackagesValidator.php @@ -6,6 +6,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\PathLocator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Validates that newly installed packages don't overwrite existing directories. @@ -15,7 +16,7 @@ use Drupal\package_manager\PathLocator; * at any time without warning. External code should not interact with this * class. */ -final class OverwriteExistingPackagesValidator implements PreOperationStageValidatorInterface { +final class OverwriteExistingPackagesValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/PendingUpdatesValidator.php b/package_manager/src/Validator/PendingUpdatesValidator.php index 588e073b11fd4a3f4ec9926e4bed7096fa38dbbb..b51e35a7534433c579acb4f5bc2fdab9e0d0c716 100644 --- a/package_manager/src/Validator/PendingUpdatesValidator.php +++ b/package_manager/src/Validator/PendingUpdatesValidator.php @@ -9,6 +9,7 @@ use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Update\UpdateRegistry; use Drupal\Core\Url; use Drupal\package_manager\Event\StatusCheckEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Validates that there are no pending database updates. @@ -18,7 +19,7 @@ use Drupal\package_manager\Event\StatusCheckEvent; * at any time without warning. External code should not interact with this * class. */ -final class PendingUpdatesValidator implements PreOperationStageValidatorInterface { +final class PendingUpdatesValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/PreOperationStageValidatorInterface.php b/package_manager/src/Validator/PreOperationStageValidatorInterface.php index a30bfbcda53117347a12b55bde192303868b734c..a49ca09f72a0bb578f66cb33129f0d8a944d5c6c 100644 --- a/package_manager/src/Validator/PreOperationStageValidatorInterface.php +++ b/package_manager/src/Validator/PreOperationStageValidatorInterface.php @@ -2,6 +2,8 @@ namespace Drupal\package_manager\Validator; +@trigger_error(__NAMESPACE__ . '\PreOperationStageValidatorInterface is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. There is no replacement. See https://www.drupal.org/node/3316086.', E_USER_DEPRECATED); + use Drupal\package_manager\Event\PreOperationStageEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/package_manager/src/Validator/SettingsValidator.php b/package_manager/src/Validator/SettingsValidator.php index 971f477dcf8ae55ba96c7d73435a2b3b8e283e87..63d9d74016439b57e8056efd7f1c51a23b51fbfe 100644 --- a/package_manager/src/Validator/SettingsValidator.php +++ b/package_manager/src/Validator/SettingsValidator.php @@ -8,6 +8,7 @@ use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\package_manager\Event\StatusCheckEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Checks that Drupal's settings are valid for Package Manager. @@ -17,7 +18,7 @@ use Drupal\package_manager\Event\StatusCheckEvent; * at any time without warning. External code should not interact with this * class. */ -final class SettingsValidator implements PreOperationStageValidatorInterface { +final class SettingsValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/SymlinkValidator.php b/package_manager/src/Validator/SymlinkValidator.php index b8b5550826ad245beae26729617ee4624a9e23da..925df7b22c7bcdda2ab073e5f5f2da47a5d0a1cf 100644 --- a/package_manager/src/Validator/SymlinkValidator.php +++ b/package_manager/src/Validator/SymlinkValidator.php @@ -13,6 +13,7 @@ use Drupal\package_manager\PathLocator; use PhpTuf\ComposerStager\Domain\Exception\PreconditionException; use PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface; use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Flags errors if the project root or staging area contain symbolic links. @@ -25,7 +26,7 @@ use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; * at any time without warning. External code should not interact with this * class. */ -class SymlinkValidator implements PreOperationStageValidatorInterface { +class SymlinkValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/src/Validator/WritableFileSystemValidator.php b/package_manager/src/Validator/WritableFileSystemValidator.php index db2ff02768a72f758ee944572779e99f1077a8d8..7badb57765be7fd42b8858c312131dc5aee3e764 100644 --- a/package_manager/src/Validator/WritableFileSystemValidator.php +++ b/package_manager/src/Validator/WritableFileSystemValidator.php @@ -8,6 +8,7 @@ use Drupal\package_manager\Event\PreOperationStageEvent; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\PathLocator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Checks that the file system is writable. @@ -17,7 +18,7 @@ use Drupal\package_manager\PathLocator; * at any time without warning. External code should not interact with this * class. */ -class WritableFileSystemValidator implements PreOperationStageValidatorInterface { +class WritableFileSystemValidator implements EventSubscriberInterface { use StringTranslationTrait; diff --git a/package_manager/tests/modules/package_manager_test_validation/src/EventSubscriber/TestSubscriber.php b/package_manager/tests/modules/package_manager_test_validation/src/EventSubscriber/TestSubscriber.php index 6a755fdb08a856532ef132820b735de9f4ca1993..80a5ac26a420b6709cb397c4a50ccfe7c630b552 100644 --- a/package_manager/tests/modules/package_manager_test_validation/src/EventSubscriber/TestSubscriber.php +++ b/package_manager/tests/modules/package_manager_test_validation/src/EventSubscriber/TestSubscriber.php @@ -114,8 +114,8 @@ class TestSubscriber implements EventSubscriberInterface { * The state key under which to store the results for the given event. */ protected static function getStateKey(string $event): string { - $parts = explode('\\', $event); - return static::STATE_KEY . array_pop($parts); + $key = hash('sha256', static::class . $event); + return static::STATE_KEY . substr($key, 0, 8); } /** diff --git a/package_manager/tests/src/Kernel/StageValidationExceptionTest.php b/package_manager/tests/src/Kernel/StageValidationExceptionTest.php index 5fe49b2b4283f47863c83cf8ad6aa813aa4f09f4..0bacff558971325f1c38c2a1630e0c4f9dc6a383 100644 --- a/package_manager/tests/src/Kernel/StageValidationExceptionTest.php +++ b/package_manager/tests/src/Kernel/StageValidationExceptionTest.php @@ -2,10 +2,10 @@ namespace Drupal\Tests\package_manager\Kernel; -use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Exception\StageValidationException; use Drupal\package_manager\ValidationResult; +use Drupal\package_manager_test_validation\EventSubscriber\TestSubscriber; /** * @coversDefaultClass \Drupal\package_manager\Exception\StageValidationException @@ -72,7 +72,7 @@ class StageValidationExceptionTest extends PackageManagerKernelTestBase { * @covers ::getResultsAsText() */ public function testResultsAsText(array $validation_results, string $expected_message): void { - TestSubscriber1::setTestResult($validation_results, PreCreateEvent::class); + TestSubscriber::setTestResult($validation_results, PreCreateEvent::class); $this->expectException(StageValidationException::class); $this->expectExceptionMessage($expected_message); $this->createStage()->create(); diff --git a/src/Event/ReadinessCheckEvent.php b/src/Event/ReadinessCheckEvent.php index 466038a10606975108e370b24cf7841f6c69bf84..1a401a7aea437b054d1afe1aef6f8409d1c18de9 100644 --- a/src/Event/ReadinessCheckEvent.php +++ b/src/Event/ReadinessCheckEvent.php @@ -38,6 +38,7 @@ class ReadinessCheckEvent extends PreOperationStageEvent { * name. */ public function __construct(Stage $stage, array $project_versions = []) { + @trigger_error(__CLASS__ . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. Use \Drupal\package_manager\Event\StatusCheckEvent instead. See https://www.drupal.org/node/3316086.', E_USER_DEPRECATED); parent::__construct($stage); if ($project_versions) { if (count($project_versions) !== 1 || !array_key_exists('drupal', $project_versions)) { diff --git a/src/Form/UpdateFormBase.php b/src/Form/UpdateFormBase.php index 1c44060b53615a71c065479cef9df355f512a92d..5f3bc2e7b1462219ace96e2a400317b3296b474c 100644 --- a/src/Form/UpdateFormBase.php +++ b/src/Form/UpdateFormBase.php @@ -5,6 +5,7 @@ namespace Drupal\automatic_updates\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Render\RendererInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\package_manager\StatusCheckTrait; use Drupal\package_manager\ValidationResult; use Drupal\system\SystemManager; @@ -17,6 +18,8 @@ use Drupal\system\SystemManager; */ abstract class UpdateFormBase extends FormBase { + use StatusCheckTrait; + /** * Gets a message, based on severity, when readiness checkers fail. * diff --git a/src/Form/UpdateReady.php b/src/Form/UpdateReady.php index a87b5197b7606631fc4d569a1bcd5f4c933cb218..ef38e164bbb39459180a8f58c4f3c094ae9d4794 100644 --- a/src/Form/UpdateReady.php +++ b/src/Form/UpdateReady.php @@ -12,7 +12,6 @@ use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\State\StateInterface; use Drupal\package_manager\Exception\ApplyFailedException; -use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\Exception\StageException; use Drupal\package_manager\Exception\StageOwnershipException; use Drupal\system\SystemManager; @@ -183,10 +182,7 @@ final class UpdateReady extends UpdateFormBase { // Don't run the status checks once the form has been submitted. if (!$form_state->getUserInput()) { - $event = new StatusCheckEvent($this->updater); - $this->eventDispatcher->dispatch($event); - /** @var \Drupal\package_manager\ValidationResult[] $results */ - $results = $event->getResults(); + $results = $this->runStatusCheck($this->updater, $this->eventDispatcher); // This will have no effect if $results is empty. $this->displayResults($results, $this->renderer); // If any errors occurred, return the form early so the user cannot diff --git a/src/Form/UpdaterForm.php b/src/Form/UpdaterForm.php index c63b3c751cd05939b09e0d8e4efee82ac628e0ef..7c8ace411e780459ee9a12eaba1d718801193b68 100644 --- a/src/Form/UpdaterForm.php +++ b/src/Form/UpdaterForm.php @@ -3,7 +3,6 @@ namespace Drupal\automatic_updates\Form; use Drupal\automatic_updates\BatchProcessor; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\package_manager\FailureMarker; use Drupal\package_manager\ProjectInfo; @@ -190,13 +189,11 @@ final class UpdaterForm extends UpdateFormBase { return $form; } - if ($form_state->getUserInput()) { + if ($form_state->getUserInput() || $stage_exists) { $results = []; } else { - $event = new ReadinessCheckEvent($this->updater); - $this->eventDispatcher->dispatch($event); - $results = $event->getResults(); + $results = $this->runStatusCheck($this->updater, $this->eventDispatcher, TRUE); } $this->displayResults($results, $this->renderer); $project = $project_info->getProjectInfo(); diff --git a/src/Validation/ReadinessValidationManager.php b/src/Validation/ReadinessValidationManager.php index 3486bcddc739f1e17bf603065e1dd92755861027..1873e412560236798ef38fb46cce7245050c81c7 100644 --- a/src/Validation/ReadinessValidationManager.php +++ b/src/Validation/ReadinessValidationManager.php @@ -3,7 +3,7 @@ namespace Drupal\automatic_updates\Validation; use Drupal\automatic_updates\CronUpdater; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; +use Drupal\package_manager\StatusCheckTrait; use Drupal\automatic_updates\Updater; use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; @@ -16,6 +16,8 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; */ final class ReadinessValidationManager implements EventSubscriberInterface { + use StatusCheckTrait; + /** * The key/value expirable storage. * @@ -90,17 +92,16 @@ final class ReadinessValidationManager implements EventSubscriberInterface { */ public function run(): self { // If updates will run during cron, use the cron updater service provided by - // this module. This will allow subscribers to ReadinessCheckEvent to run - // specific validation for conditions that only affect cron updates. + // this module. This will allow validators to run specific validation for + // conditions that only affect cron updates. if ($this->cronUpdater->getMode() === CronUpdater::DISABLED) { $stage = $this->updater; } else { $stage = $this->cronUpdater; } - $event = new ReadinessCheckEvent($stage); - $this->eventDispatcher->dispatch($event); - $results = $event->getResults(); + $results = $this->runStatusCheck($stage, $this->eventDispatcher, TRUE); + $this->keyValueExpirable->setWithExpire( 'readiness_validation_last_run', $results, diff --git a/src/Validator/CronFrequencyValidator.php b/src/Validator/CronFrequencyValidator.php index b7e545ffcec3ead4e225322bfec470fc7e70e077..c7fe3ae4807bf574c5cf999d78291fae82a20348 100644 --- a/src/Validator/CronFrequencyValidator.php +++ b/src/Validator/CronFrequencyValidator.php @@ -3,7 +3,6 @@ namespace Drupal\automatic_updates\Validator; use Drupal\automatic_updates\CronUpdater; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -11,6 +10,7 @@ use Drupal\Core\State\StateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Url; +use Drupal\package_manager\Event\StatusCheckEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -115,10 +115,10 @@ class CronFrequencyValidator implements EventSubscriberInterface { /** * Validates that cron runs frequently enough to perform automatic updates. * - * @param \Drupal\automatic_updates\Event\ReadinessCheckEvent $event + * @param \Drupal\package_manager\Event\StatusCheckEvent $event * The event object. */ - public function checkCronFrequency(ReadinessCheckEvent $event): void { + public function checkCronFrequency(StatusCheckEvent $event): void { // We only want to do this check if the stage belongs to Automatic Updates. if (!$event->getStage() instanceof CronUpdater) { return; @@ -139,10 +139,10 @@ class CronFrequencyValidator implements EventSubscriberInterface { /** * Validates the cron frequency according to Automated Cron settings. * - * @param \Drupal\automatic_updates\Event\ReadinessCheckEvent $event + * @param \Drupal\package_manager\Event\StatusCheckEvent $event * The event object. */ - protected function validateAutomatedCron(ReadinessCheckEvent $event): void { + protected function validateAutomatedCron(StatusCheckEvent $event): void { $message = $this->t('Cron is not set to run frequently enough. <a href=":configure">Configure it</a> to run at least every @frequency hours or disable automated cron and run it via an external scheduling system.', [ ':configure' => Url::fromRoute('system.cron_settings')->toString(), '@frequency' => static::SUGGESTED_INTERVAL, @@ -161,10 +161,10 @@ class CronFrequencyValidator implements EventSubscriberInterface { /** * Validates the cron frequency according to the last cron run time. * - * @param \Drupal\automatic_updates\Event\ReadinessCheckEvent $event + * @param \Drupal\package_manager\Event\StatusCheckEvent $event * The event object. */ - protected function validateLastCronRun(ReadinessCheckEvent $event): void { + protected function validateLastCronRun(StatusCheckEvent $event): void { // Determine when cron last ran. If not known, use the time that Drupal was // installed, defaulting to the beginning of the Unix epoch. $cron_last = $this->state->get('system.cron_last', $this->state->get('install_time', 0)); @@ -189,7 +189,7 @@ class CronFrequencyValidator implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - ReadinessCheckEvent::class => 'checkCronFrequency', + StatusCheckEvent::class => 'checkCronFrequency', ]; } diff --git a/src/Validator/CronServerValidator.php b/src/Validator/CronServerValidator.php index 5d2ce9fc46de00a2c828ac606be6bdc6f693eb51..ac3fa0bd45a0c37ce2ef2aac98dccc7f7f1050da 100644 --- a/src/Validator/CronServerValidator.php +++ b/src/Validator/CronServerValidator.php @@ -3,7 +3,6 @@ namespace Drupal\automatic_updates\Validator; use Drupal\automatic_updates\CronUpdater; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Http\RequestStack; @@ -11,6 +10,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; +use Drupal\package_manager\Event\StatusCheckEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -115,8 +115,8 @@ final class CronServerValidator implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - ReadinessCheckEvent::class => 'checkServer', PreCreateEvent::class => 'checkServer', + StatusCheckEvent::class => 'checkServer', ]; } diff --git a/src/Validator/PackageManagerReadinessCheck.php b/src/Validator/PackageManagerReadinessCheck.php deleted file mode 100644 index e562b6cea4d4552dc689a23907202c76a294ecb7..0000000000000000000000000000000000000000 --- a/src/Validator/PackageManagerReadinessCheck.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -namespace Drupal\automatic_updates\Validator; - -use Drupal\automatic_updates\Event\ReadinessCheckEvent; -use Drupal\automatic_updates\Updater; -use Drupal\package_manager\Validator\PreOperationStageValidatorInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -/** - * An adapter to run another stage validator during readiness checking. - * - * This class exists to facilitate re-use of Package Manager's stage validators - * during update readiness checks, in addition to whatever events they normally - * subscribe to. - * - * @internal - * This is an internal part of Automatic Updates and may be changed or removed - * at any time without warning. External code should not interact with this - * class. - */ -final class PackageManagerReadinessCheck implements EventSubscriberInterface { - - /** - * The validator to run. - * - * @var \Drupal\package_manager\Validator\PreOperationStageValidatorInterface - */ - protected $validator; - - /** - * Constructs a PackageManagerReadinessCheck object. - * - * @param \Drupal\package_manager\Validator\PreOperationStageValidatorInterface $validator - * The Package Manager validator to run during readiness checking. - */ - public function __construct(PreOperationStageValidatorInterface $validator) { - $this->validator = $validator; - } - - /** - * Performs a readiness check by proxying to a Package Manager validator. - * - * @param \Drupal\automatic_updates\Event\ReadinessCheckEvent $event - * The event object. - */ - public function validate(ReadinessCheckEvent $event): void { - // We only want to do this check if the stage belongs to Automatic Updates. - if (!$event->getStage() instanceof Updater) { - return; - } - $this->validator->validateStagePreOperation($event); - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - return [ - ReadinessCheckEvent::class => 'validate', - ]; - } - -} diff --git a/src/Validator/ScaffoldFilePermissionsValidator.php b/src/Validator/ScaffoldFilePermissionsValidator.php index 078a6cf01fa7175a0a2046b8af9c6009597bda20..2e214909f352252f1f8bd18f84818e2cb7e6e7f9 100644 --- a/src/Validator/ScaffoldFilePermissionsValidator.php +++ b/src/Validator/ScaffoldFilePermissionsValidator.php @@ -2,15 +2,15 @@ namespace Drupal\automatic_updates\Validator; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Updater; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\ComposerUtility; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; +use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\PathLocator; -use Drupal\package_manager\Validator\PreOperationStageValidatorInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Validates that scaffold files have appropriate permissions. @@ -20,7 +20,7 @@ use Drupal\package_manager\Validator\PreOperationStageValidatorInterface; * at any time without warning. External code should not interact with this * class. */ -final class ScaffoldFilePermissionsValidator implements PreOperationStageValidatorInterface { +final class ScaffoldFilePermissionsValidator implements EventSubscriberInterface { use StringTranslationTrait; @@ -128,9 +128,9 @@ final class ScaffoldFilePermissionsValidator implements PreOperationStageValidat */ public static function getSubscribedEvents() { return [ - ReadinessCheckEvent::class => 'validateStagePreOperation', PreCreateEvent::class => 'validateStagePreOperation', PreApplyEvent::class => 'validateStagePreOperation', + StatusCheckEvent::class => 'validateStagePreOperation', ]; } diff --git a/src/Validator/VersionPolicyValidator.php b/src/Validator/VersionPolicyValidator.php index 15f67b8cc4a1970d495ab0eac3f7ce56b98a549e..3ca70907ce1d18ddf2c0cc4c1ec60f82aadc89ce 100644 --- a/src/Validator/VersionPolicyValidator.php +++ b/src/Validator/VersionPolicyValidator.php @@ -3,7 +3,7 @@ namespace Drupal\automatic_updates\Validator; use Drupal\automatic_updates\CronUpdater; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; +use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\package_manager\ProjectInfo; use Drupal\automatic_updates\Updater; use Drupal\automatic_updates\Validator\VersionPolicy\ForbidDowngrade; @@ -178,23 +178,22 @@ final class VersionPolicyValidator implements EventSubscriberInterface { * @throws \LogicException * Thrown if the target version cannot be determined due to unexpected * conditions. This can happen if, during a stage life cycle event (i.e., - * NOT a readiness check), the event or updater does not have a list of - * desired package versions, or the list of package versions does not - * include any Drupal core packages. + * NOT a status check), the event or updater does not have a list of desired + * package versions, or the list of package versions does not include any + * Drupal core packages. */ private function getTargetVersion(StageEvent $event): ?string { $updater = $event->getStage(); - if ($event instanceof ReadinessCheckEvent) { - $package_versions = $event->getPackageVersions(); - } - else { + // If we're not doing a status check, we expect the stage to have been + // created, and the requested package versions recorded. + if (!$event instanceof StatusCheckEvent) { $package_versions = $updater->getPackageVersions()['production']; } $unknown_target = new \LogicException('The target version of Drupal core could not be determined.'); - if ($package_versions) { + if (isset($package_versions)) { $core_package_name = key($updater->getActiveComposer()->getCorePackages()); if ($core_package_name && array_key_exists($core_package_name, $package_versions)) { @@ -204,7 +203,7 @@ final class VersionPolicyValidator implements EventSubscriberInterface { throw $unknown_target; } } - elseif ($event instanceof ReadinessCheckEvent) { + elseif ($event instanceof StatusCheckEvent) { if ($updater instanceof CronUpdater) { $target_release = $updater->getTargetRelease(); if ($target_release) { @@ -256,8 +255,8 @@ final class VersionPolicyValidator implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - ReadinessCheckEvent::class => 'checkVersion', PreCreateEvent::class => 'checkVersion', + StatusCheckEvent::class => 'checkVersion', ]; } diff --git a/src/Validator/XdebugValidator.php b/src/Validator/XdebugValidator.php index e8d842331b202917aff901a20c059d078649c30a..28446ea6b9bade736ebb70ca4ba97437753e7f94 100644 --- a/src/Validator/XdebugValidator.php +++ b/src/Validator/XdebugValidator.php @@ -4,7 +4,6 @@ namespace Drupal\automatic_updates\Validator; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\automatic_updates\CronUpdater; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Updater; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; @@ -64,7 +63,7 @@ final class XdebugValidator implements EventSubscriberInterface { $event->addError($result->getMessages(), $result->getSummary()); } } - elseif ($event instanceof ReadinessCheckEvent) { + elseif ($event instanceof StatusCheckEvent) { // For non-cron updates provide a warning but do not stop updates from // executing. foreach ($results as $result) { @@ -78,8 +77,8 @@ final class XdebugValidator implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - ReadinessCheckEvent::class => 'checkForXdebug', PreCreateEvent::class => 'checkForXdebug', + StatusCheckEvent::class => 'checkForXdebug', ]; } diff --git a/tests/modules/automatic_updates_test/src/EventSubscriber/TestSubscriber1.php b/tests/modules/automatic_updates_test/src/EventSubscriber/TestSubscriber1.php index 4e68a19c457cc601c2aa19a6da9ccb1f3a7a0637..31771a2c27f39e228efc53f7f88dfddbc1ddc094 100644 --- a/tests/modules/automatic_updates_test/src/EventSubscriber/TestSubscriber1.php +++ b/tests/modules/automatic_updates_test/src/EventSubscriber/TestSubscriber1.php @@ -2,21 +2,10 @@ namespace Drupal\automatic_updates_test\EventSubscriber; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\package_manager_test_validation\EventSubscriber\TestSubscriber; /** * A test readiness checker. */ class TestSubscriber1 extends TestSubscriber { - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - $events = parent::getSubscribedEvents(); - $events[ReadinessCheckEvent::class] = reset($events); - return $events; - } - } diff --git a/tests/modules/automatic_updates_test2/src/EventSubscriber/TestSubscriber2.php b/tests/modules/automatic_updates_test2/src/EventSubscriber/TestSubscriber2.php index c03d4bb92b1c21b2c2badc1eadc558925a2d07aa..47863fcef54cb9eaa7dbe26c47e846537b138372 100644 --- a/tests/modules/automatic_updates_test2/src/EventSubscriber/TestSubscriber2.php +++ b/tests/modules/automatic_updates_test2/src/EventSubscriber/TestSubscriber2.php @@ -2,9 +2,9 @@ namespace Drupal\automatic_updates_test2\EventSubscriber; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\package_manager\Event\PreCreateEvent; +use Drupal\package_manager\Event\StatusCheckEvent; /** * A test readiness checker. @@ -14,7 +14,7 @@ class TestSubscriber2 extends TestSubscriber1 { protected const STATE_KEY = 'automatic_updates_test2.checker_results'; public static function getSubscribedEvents() { - $events[ReadinessCheckEvent::class][] = ['handleEvent', 4]; + $events[StatusCheckEvent::class][] = ['handleEvent', 4]; $events[PreCreateEvent::class][] = ['handleEvent', 4]; return $events; diff --git a/tests/src/Functional/ReadinessValidationTest.php b/tests/src/Functional/ReadinessValidationTest.php index cbb06f50f4bc541d6ac3dd498bea4b8e71da7d85..2acbf7efa6dfbaf1ab71acb9e42c19abe5322ec9 100644 --- a/tests/src/Functional/ReadinessValidationTest.php +++ b/tests/src/Functional/ReadinessValidationTest.php @@ -3,11 +3,11 @@ namespace Drupal\Tests\automatic_updates\Functional; use Behat\Mink\Element\NodeElement; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates_test\Datetime\TestTime; use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2; use Drupal\Core\Url; +use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\system\SystemManager; use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait; use Drupal\Tests\Traits\Core\CronRunTrait; @@ -115,7 +115,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $this->assertNoErrors(TRUE); /** @var \Drupal\package_manager\ValidationResult[] $expected_results */ $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); // Run the readiness checks. $this->clickLink('Run readiness checks'); @@ -139,7 +139,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { 'error' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR), 'warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING), ]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); // Confirm a new message is displayed if the page is reloaded. $this->getSession()->reload(); // Confirm that on the status page if there is only 1 warning or error the @@ -153,7 +153,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { 'error' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2), 'warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2), ]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); $this->getSession()->reload(); // Confirm that both messages and summaries will be displayed on status // report when there multiple messages. @@ -161,7 +161,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $this->assertWarnings([$expected_results['warning']]); $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); $this->getSession()->reload(); $assert->pageTextContainsOnce('Update readiness checks'); // Confirm that warnings will display on the status report if there are no @@ -169,7 +169,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $this->assertWarnings($expected_results); $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); $this->getSession()->reload(); $assert->pageTextContainsOnce('Update readiness checks'); $this->assertWarnings($expected_results); @@ -198,7 +198,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { // Confirm a user without the permission to run readiness checks does not // have a link to run the checks when the checks need to be run again. $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); // @todo Change this to use ::delayRequestTime() to simulate running cron // after a 24 wait instead of directly deleting 'readiness_validation_last_run' // https://www.drupal.org/node/3113971. @@ -224,7 +224,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { '1 error' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR), '1 warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING), ]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); // Confirm a new message is displayed if the cron is run after an hour. $this->delayRequestTime(); $this->cronRun(); @@ -246,7 +246,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { '2 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2), '2 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2), ]; - TestSubscriber1::setTestResult($unexpected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($unexpected_results, StatusCheckEvent::class); $this->delayRequestTime(30); $this->cronRun(); $this->drupalGet('admin/structure'); @@ -275,7 +275,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $assert->pageTextNotContains($expected_results['2 warnings']->getSummary()); $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); $this->delayRequestTime(); $this->cronRun(); $this->drupalGet('admin/structure'); @@ -289,7 +289,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $assert->pageTextContainsOnce($expected_results[0]->getSummary()); $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); $this->delayRequestTime(); $this->cronRun(); $this->drupalGet('admin/structure'); @@ -328,7 +328,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $this->assertNoErrors(TRUE); $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber2::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber2::setTestResult($expected_results, StatusCheckEvent::class); $this->container->get('module_installer')->install(['automatic_updates_test2']); $this->drupalGet('admin/structure'); $assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]); @@ -340,7 +340,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { '2 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2), '2 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2), ]; - TestSubscriber2::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber2::setTestResult($expected_results, StatusCheckEvent::class); $this->container->get('module_installer')->install(['help']); // Check for messages on 'admin/structure' instead of the status report, // because validators will be run if needed on the status report. @@ -359,9 +359,9 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { $this->drupalLogin($this->checkerRunnerUser); $expected_results_1 = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($expected_results_1, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results_1, StatusCheckEvent::class); $expected_results_2 = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber2::setTestResult($expected_results_2, ReadinessCheckEvent::class); + TestSubscriber2::setTestResult($expected_results_2, StatusCheckEvent::class); $this->container->get('module_installer')->install([ 'automatic_updates', 'automatic_updates_test', @@ -402,7 +402,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { // Flag a validation error, which will be displayed in the messages area. $results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($results, StatusCheckEvent::class); $message = $results[0]->getMessages()[0]; $this->container->get('module_installer')->install([ @@ -414,7 +414,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { // flagging it. $this->drupalGet('/admin/structure'); $assert_session->pageTextContains($message); - TestSubscriber1::setTestResult(NULL, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult(NULL, StatusCheckEvent::class); $this->getSession()->reload(); $assert_session->pageTextContains($message); diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php index 6c3cf7ed8f932c21c178ffa98147ea713ccbcebe..13de205a31cbd47c5fb357a7be1a3d9a9d3f54ac 100644 --- a/tests/src/Functional/UpdaterFormTest.php +++ b/tests/src/Functional/UpdaterFormTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\automatic_updates\Functional; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates_test\Datetime\TestTime; use Drupal\package_manager_test_validation\StagedDatabaseUpdateValidator; use Drupal\package_manager\Event\PostRequireEvent; @@ -222,7 +221,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->setCoreVersion('9.8.1'); $message = "You've not experienced Shakespeare until you have read him in the original Klingon."; $result = ValidationResult::createError([$message]); - TestSubscriber1::setTestResult([$result], ReadinessCheckEvent::class); + TestSubscriber1::setTestResult([$result], StatusCheckEvent::class); $this->checkForUpdates(); $this->drupalGet('/admin/reports/updates/automatic-update'); $assert_session->pageTextContains('No update available'); @@ -284,7 +283,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Set up a new fake error. Use an error with multiple messages so we can // ensure that they're all displayed, along with their summary. $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); // If a validator raises an error during readiness checking, the form should // not have a submit button. @@ -300,7 +299,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $assert_session->pageTextContainsOnce(static::$errorsExplanation); $assert_session->pageTextNotContains(static::$warningsExplanation); $assert_session->pageTextNotContains($cached_message); - TestSubscriber1::setTestResult(NULL, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult(NULL, StatusCheckEvent::class); // Make the validator throw an exception during pre-create. $error = new \Exception('The update exploded.'); @@ -538,7 +537,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Flag a warning, which will not block the update but should be displayed // on the updater form. $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); $messages = reset($expected_results)->getMessages(); StagedDatabaseUpdateValidator::setExtensionsWithUpdates(['system', 'automatic_updates_theme_with_updates']); @@ -558,11 +557,11 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // We must do this after the update has started, because the pending updates // validator will prevent an update from starting. $state->set('automatic_updates_test.new_update', TRUE); - // The warning from the updater form should be not be repeated, but we - // should see a warning about pending database updates, and once the staged - // changes have been applied, we should be redirected to update.php, where - // neither warning should be visible. - $assert_session->pageTextNotContains(reset($messages)); + // The warning from the updater form should be repeated, and we should see + // a warning about pending database updates. Once the staged changes have + // been applied, we should be redirected to update.php, where neither + // warning should be visible. + $assert_session->pageTextContains(reset($messages)); // Ensure that a list of pending database updates is visible, along with a // short explanation, in the warning messages. @@ -852,7 +851,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Store a readiness error, which will be cached. $message = "You've not experienced Shakespeare until you have read him in the original Klingon."; $result = ValidationResult::createError([$message]); - TestSubscriber1::setTestResult([$result], ReadinessCheckEvent::class); + TestSubscriber1::setTestResult([$result], StatusCheckEvent::class); // Run the readiness checks a visit an admin page the message will be // displayed. $this->drupalGet('/admin/reports/status'); @@ -861,7 +860,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->assertSession()->pageTextContains($message); // Clear the results so the only way the message could appear on the pages // used for the update process is if they show the cached results. - TestSubscriber1::setTestResult(NULL, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult(NULL, StatusCheckEvent::class); return $message; } diff --git a/tests/src/Kernel/CronUpdaterTest.php b/tests/src/Kernel/CronUpdaterTest.php index da321e21b67e6ea65a068747e31e458754610dee..fc800ad03e0b5487a2e92ff9db5906138d271039 100644 --- a/tests/src/Kernel/CronUpdaterTest.php +++ b/tests/src/Kernel/CronUpdaterTest.php @@ -290,14 +290,10 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase { 'drupal' => __DIR__ . "/../../../package_manager/tests/fixtures/release-history/drupal.9.8.1-security.xml", ]); - // Disable the symlink validators so that this test isn't affected by + // Disable the symlink validator so that this test isn't affected by // symlinks that might be present in the running code base. - $validators = [ - 'automatic_updates.validator.symlink', - 'package_manager.validator.symlink', - ]; - $validators = array_map([$this->container, 'get'], $validators); - array_walk($validators, [$this->container->get('event_dispatcher'), 'removeSubscriber']); + $validator = $this->container->get('package_manager.validator.symlink'); + $this->container->get('event_dispatcher')->removeSubscriber($validator); // If the pre- or post-destroy events throw an exception, it will not be // caught by the cron updater, but it *will* be caught by the main cron @@ -521,7 +517,7 @@ END; } /** - * Asserts that all recipients recieved a given email. + * Asserts that all recipients received a given email. * * @param string $subject * The subject line of the email that should have been sent. diff --git a/tests/src/Kernel/ReadinessCheckTest.php b/tests/src/Kernel/ReadinessCheckTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fac38a584a60fce13e55e267a2fe503213a8c0ea --- /dev/null +++ b/tests/src/Kernel/ReadinessCheckTest.php @@ -0,0 +1,48 @@ +<?php + +namespace Drupal\Tests\automatic_updates\Kernel; + +use Drupal\automatic_updates\Event\ReadinessCheckEvent; +use Drupal\package_manager\StatusCheckTrait; + +/** + * Tests that running readiness checks raises deprecation notices. + * + * @group legacy + */ +class ReadinessCheckTest extends AutomaticUpdatesKernelTestBase { + + use StatusCheckTrait; + + /** + * {@inheritdoc} + */ + protected static $modules = ['automatic_updates']; + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + $this->container->get('event_dispatcher') + ->addListener(ReadinessCheckEvent::class, function () {}); + } + + /** + * Tests running readiness check via StatusCheckTrait. + */ + public function testStatusCheckTrait(): void { + $this->expectDeprecation(ReadinessCheckEvent::class . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. Use \Drupal\package_manager\Event\StatusCheckEvent instead. See https://www.drupal.org/node/3316086.'); + $this->runStatusCheck($this->createStage(), $this->container->get('event_dispatcher'), TRUE); + } + + /** + * Tests running readiness checks using the readiness validation manager. + */ + public function testReadinessValidationManager(): void { + $this->expectDeprecation(ReadinessCheckEvent::class . ' is deprecated in automatic_updates:8.x-2.5 and will be removed in automatic_updates:3.0.0. Use \Drupal\package_manager\Event\StatusCheckEvent instead. See https://www.drupal.org/node/3316086.'); + $this->assertCheckerResultsFromManager([], TRUE); + } + +} diff --git a/tests/src/Kernel/ReadinessValidation/CronFrequencyValidatorTest.php b/tests/src/Kernel/ReadinessValidation/CronFrequencyValidatorTest.php index febd0442217b8b09cae5501291ab6ee0cbb37daf..38fd62344b759f070b8fe7b48a62f64fcf80615a 100644 --- a/tests/src/Kernel/ReadinessValidation/CronFrequencyValidatorTest.php +++ b/tests/src/Kernel/ReadinessValidation/CronFrequencyValidatorTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation; use Drupal\automatic_updates\CronUpdater; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Validator\CronFrequencyValidator; use Drupal\package_manager\ValidationResult; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; @@ -55,14 +54,14 @@ class CronFrequencyValidatorTest extends AutomaticUpdatesKernelTestBase { /** * {@inheritdoc} */ - protected function validateAutomatedCron(ReadinessCheckEvent $event): void { + protected function validateAutomatedCron($event): void { throw new AssertionFailedError(__METHOD__ . '() should not have been called.'); } /** * {@inheritdoc} */ - protected function validateLastCronRun(ReadinessCheckEvent $event): void { + protected function validateLastCronRun($event): void { throw new AssertionFailedError(__METHOD__ . '() should not have been called.'); } diff --git a/tests/src/Kernel/ReadinessValidation/PackageManagerReadinessChecksTest.php b/tests/src/Kernel/ReadinessValidation/PackageManagerReadinessChecksTest.php deleted file mode 100644 index 96296a11b58d4067d5bfc4a80761de0b63bf80a9..0000000000000000000000000000000000000000 --- a/tests/src/Kernel/ReadinessValidation/PackageManagerReadinessChecksTest.php +++ /dev/null @@ -1,82 +0,0 @@ -<?php - -namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation; - -use Drupal\automatic_updates\Event\ReadinessCheckEvent; -use Drupal\package_manager\Validator\PreOperationStageValidatorInterface; -use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; -use Prophecy\Argument; - -/** - * Tests that Package Manager validators are invoked during readiness checking. - * - * @group automatic_updates - * - * @covers \Drupal\automatic_updates\Validator\PackageManagerReadinessCheck - * - * @see \Drupal\Tests\package_manager\Kernel\ComposerExecutableValidatorTest - * @see \Drupal\Tests\package_manager\Kernel\DiskSpaceValidatorTest - * @see \Drupal\Tests\package_manager\Kernel\PendingUpdatesValidatorTest - * @see \Drupal\Tests\package_manager\Kernel\WritableFileSystemValidatorTest - */ -class PackageManagerReadinessChecksTest extends AutomaticUpdatesKernelTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = [ - 'automatic_updates', - 'package_manager', - ]; - - /** - * {@inheritdoc} - */ - protected $disableValidators = [ - // The parent class disables one of the validators that we're testing, so - // prevent that with an empty array. - ]; - - /** - * Data provider for testValidatorInvoked(). - * - * @return string[][] - * The test cases. - */ - public function providerValidatorInvoked(): array { - return [ - 'Composer executable validator' => ['package_manager.validator.composer_executable'], - 'Disk space validator' => ['package_manager.validator.disk_space'], - 'Pending updates validator' => ['package_manager.validator.pending_updates'], - 'File system validator' => ['package_manager.validator.file_system'], - 'Composer settings validator' => ['package_manager.validator.composer_settings'], - 'Multisite validator' => ['package_manager.validator.multisite'], - 'Symlink validator' => ['package_manager.validator.symlink'], - 'Settings validator' => ['package_manager.validator.settings'], - 'Patches validator' => ['package_manager.validator.patches'], - 'Environment support validator' => ['package_manager.validator.environment_support'], - ]; - } - - /** - * Tests that a Package Manager validator is invoked during readiness checks. - * - * @param string $service_id - * The service ID of the validator that should be invoked. - * - * @dataProvider providerValidatorInvoked - */ - public function testValidatorInvoked(string $service_id): void { - // Set up a mocked version of the Composer executable validator, to prove - // that it gets called with a readiness check event, when we run readiness - // checks. - $event = Argument::type(ReadinessCheckEvent::class); - $validator = $this->prophesize(PreOperationStageValidatorInterface::class); - $validator->validateStagePreOperation($event)->shouldBeCalled(); - $this->container->set($service_id, $validator->reveal()); - - $this->container->get('automatic_updates.readiness_validation_manager') - ->run(); - } - -} diff --git a/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php b/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php index b4ed72ae220ed75cdeb267109e0b8e392527e460..14e7bf57e88dd1b22898f9309356610713a6bd7c 100644 --- a/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php +++ b/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php @@ -3,10 +3,10 @@ namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation; use Drupal\automatic_updates\CronUpdater; -use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Updater; use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2; +use Drupal\package_manager\Event\StatusCheckEvent; use Drupal\system\SystemManager; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; @@ -43,8 +43,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { $this->assertCheckerResultsFromManager([], TRUE); $checker_1_expected = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; $checker_2_expected = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($checker_1_expected, ReadinessCheckEvent::class); - TestSubscriber2::setTestResult($checker_2_expected, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_expected, StatusCheckEvent::class); + TestSubscriber2::setTestResult($checker_2_expected, StatusCheckEvent::class); $expected_results_all = array_merge($checker_1_expected, $checker_2_expected); $this->assertCheckerResultsFromManager($expected_results_all, TRUE); @@ -69,8 +69,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { 'checker 2 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR), 'checker 2 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING), ]; - TestSubscriber1::setTestResult($checker_1_expected, ReadinessCheckEvent::class); - TestSubscriber2::setTestResult($checker_2_expected, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_expected, StatusCheckEvent::class); + TestSubscriber2::setTestResult($checker_2_expected, StatusCheckEvent::class); $expected_results_all = array_merge($checker_2_expected, $checker_1_expected); $this->assertCheckerResultsFromManager($expected_results_all, TRUE); @@ -93,7 +93,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { */ public function testRunOnInstall(): void { $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_results, StatusCheckEvent::class); // Confirm that messages from an existing module are displayed when // 'automatic_updates' is installed. $this->container->get('module_installer')->install(['automatic_updates']); @@ -103,8 +103,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { // checker is installed. $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; $checker_2_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class); - TestSubscriber2::setTestResult($checker_2_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_results, StatusCheckEvent::class); + TestSubscriber2::setTestResult($checker_2_results, StatusCheckEvent::class); $this->container->get('module_installer')->install(['automatic_updates_test2']); $expected_results_all = array_merge($checker_1_results, $checker_2_results); $this->assertCheckerResultsFromManager($expected_results_all); @@ -113,8 +113,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { // readiness checker is installed. $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; $checker_2_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class); - TestSubscriber2::setTestResult($checker_2_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_results, StatusCheckEvent::class); + TestSubscriber2::setTestResult($checker_2_results, StatusCheckEvent::class); $expected_results_all = array_merge($checker_1_results, $checker_2_results); $this->container->get('module_installer')->install(['help']); $this->assertCheckerResultsFromManager($expected_results_all); @@ -126,8 +126,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { public function testRunOnUninstall(): void { $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; $checker_2_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class); - TestSubscriber2::setTestResult($checker_2_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_results, StatusCheckEvent::class); + TestSubscriber2::setTestResult($checker_2_results, StatusCheckEvent::class); // Confirm that messages from existing modules are displayed when // 'automatic_updates' is installed. $this->container->get('module_installer')->install(['automatic_updates', 'automatic_updates_test2', 'help']); @@ -138,15 +138,15 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { // checker is uninstalled. $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; $checker_2_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class); - TestSubscriber2::setTestResult($checker_2_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_results, StatusCheckEvent::class); + TestSubscriber2::setTestResult($checker_2_results, StatusCheckEvent::class); $this->container->get('module_installer')->uninstall(['automatic_updates_test2']); $this->assertCheckerResultsFromManager($checker_1_results); // Confirm that the checkers are run when a module that does not provide a // readiness checker is uninstalled. $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($checker_1_results, StatusCheckEvent::class); $this->container->get('module_installer')->uninstall(['help']); $this->assertCheckerResultsFromManager($checker_1_results); } @@ -157,12 +157,12 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { */ public function testRunIfNeeded(): void { $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class); $this->container->get('module_installer')->install(['automatic_updates', 'automatic_updates_test2']); $this->assertCheckerResultsFromManager($expected_results); $unexpected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($unexpected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($unexpected_results, StatusCheckEvent::class); $manager = $this->container->get('automatic_updates.readiness_validation_manager'); // Confirm that the new results will not be returned because the checkers // will not be run. @@ -178,7 +178,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { // Confirm that the results are the same after rebuilding the container. $unexpected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($unexpected_results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($unexpected_results, StatusCheckEvent::class); /** @var \Drupal\Core\DrupalKernel $kernel */ $kernel = $this->container->get('kernel'); $this->container = $kernel->rebuildContainer(); @@ -191,11 +191,11 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { public function testCronSetting(): void { $this->enableModules(['automatic_updates']); $stage = NULL; - $listener = function (ReadinessCheckEvent $event) use (&$stage): void { + $listener = function (StatusCheckEvent $event) use (&$stage): void { $stage = $event->getStage(); }; $event_dispatcher = $this->container->get('event_dispatcher'); - $event_dispatcher->addListener(ReadinessCheckEvent::class, $listener); + $event_dispatcher->addListener(StatusCheckEvent::class, $listener); $this->container->get('automatic_updates.readiness_validation_manager')->run(); // By default, updates will be enabled on cron. $this->assertInstanceOf(CronUpdater::class, $stage); @@ -219,14 +219,14 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { // The readiness checker should raise a warning, so that the update is not // blocked or aborted. $results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)]; - TestSubscriber1::setTestResult($results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($results, StatusCheckEvent::class); // Ensure that the validation manager collects the warning. /** @var \Drupal\automatic_updates\Validation\ReadinessValidationManager $manager */ $manager = $this->container->get('automatic_updates.readiness_validation_manager') ->run(); $this->assertValidationResultsEqual($results, $manager->getResults()); - TestSubscriber1::setTestResult(NULL, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult(NULL, StatusCheckEvent::class); // Even though the checker no longer returns any results, the previous // results should be stored. $this->assertValidationResultsEqual($results, $manager->getResults()); @@ -261,7 +261,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { $this->enableModules(['automatic_updates']); $results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)]; - TestSubscriber1::setTestResult($results, ReadinessCheckEvent::class); + TestSubscriber1::setTestResult($results, StatusCheckEvent::class); $this->assertCheckerResultsFromManager($results, TRUE); // The results should be stored. $this->assertCheckerResultsFromManager($results, FALSE); diff --git a/tests/src/Kernel/UpdaterTest.php b/tests/src/Kernel/UpdaterTest.php index bcd4c684c8c60946564332a2df70047d26e65e67..693d12bcce19c1c5f26b66ee33ac0c0fb8d1e666 100644 --- a/tests/src/Kernel/UpdaterTest.php +++ b/tests/src/Kernel/UpdaterTest.php @@ -3,13 +3,13 @@ namespace Drupal\Tests\automatic_updates\Kernel; use Drupal\automatic_updates\Exception\UpdateException; +use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreRequireEvent; use Drupal\package_manager\Exception\StageException; use Drupal\package_manager\ValidationResult; use Drupal\package_manager_bypass\Committer; -use Drupal\package_manager_test_validation\EventSubscriber\TestSubscriber; use Drupal\Tests\user\Traits\UserCreationTrait; use PhpTuf\ComposerStager\Domain\Exception\InvalidArgumentException; @@ -214,7 +214,7 @@ class UpdaterTest extends AutomaticUpdatesKernelTestBase { $results = [ ValidationResult::createError(['An error of some sorts.']), ]; - TestSubscriber::setTestResult($results, $event_class); + TestSubscriber1::setTestResult($results, $event_class); try { $updater->begin(['drupal' => '9.8.1']); $updater->stage();