From 015b00ae27519fdfb9914477dedb5581038c0bc6 Mon Sep 17 00:00:00 2001
From: tedbow <tedbow@240860.no-reply.drupal.org>
Date: Thu, 14 Jul 2022 21:36:16 +0000
Subject: [PATCH] Issue #3295830 by tedbow, phenaproxima: Replace
 ValidationTestTrait::createTestValidationResults() with something that makes
 sense

---
 .../Functional/ReadinessValidationTest.php    |  98 +++++++++-------
 tests/src/Functional/UpdaterFormTest.php      |  10 +-
 .../ReadinessValidationManagerTest.php        | 109 ++++++++----------
 .../VersionPolicyValidatorTest.php            |  26 ++---
 tests/src/Traits/ValidationTestTrait.php      |  83 ++++---------
 5 files changed, 148 insertions(+), 178 deletions(-)

diff --git a/tests/src/Functional/ReadinessValidationTest.php b/tests/src/Functional/ReadinessValidationTest.php
index 46e48cccde..6be987720e 100644
--- a/tests/src/Functional/ReadinessValidationTest.php
+++ b/tests/src/Functional/ReadinessValidationTest.php
@@ -67,7 +67,6 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
       'access administration pages',
       'access site in maintenance mode',
     ]);
-    $this->createTestValidationResults();
     $this->drupalLogin($this->reportViewerUser);
   }
 
@@ -116,7 +115,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalGet('admin/reports/status');
     $this->assertNoErrors(TRUE);
     /** @var \Drupal\package_manager\ValidationResult[] $expected_results */
-    $expected_results = $this->testResults['checker_1']['1 error'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
 
     // Run the readiness checks.
@@ -137,29 +136,35 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalGet('admin/reports/status');
     $this->assertErrors($expected_results);
 
-    $expected_results = $this->testResults['checker_1']['1 error 1 warning'];
+    $expected_results = [
+      'error' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR),
+      'warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING),
+    ];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $key_value->delete('readiness_validation_last_run');
     // Confirm a new message is displayed if the stored messages are deleted.
     $this->drupalGet('admin/reports/status');
     // Confirm that on the status page if there is only 1 warning or error the
     // the summaries will not be displayed.
-    $this->assertErrors([$expected_results['1:error']]);
-    $this->assertWarnings([$expected_results['1:warning']]);
-    $assert->pageTextNotContains($expected_results['1:error']->getSummary());
-    $assert->pageTextNotContains($expected_results['1:warning']->getSummary());
+    $this->assertErrors([$expected_results['error']]);
+    $this->assertWarnings([$expected_results['warning']]);
+    $assert->pageTextNotContains($expected_results['error']->getSummary());
+    $assert->pageTextNotContains($expected_results['warning']->getSummary());
 
     $key_value->delete('readiness_validation_last_run');
-    $expected_results = $this->testResults['checker_1']['2 errors 2 warnings'];
+    $expected_results = [
+      'error' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2),
+      'warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2),
+    ];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->drupalGet('admin/reports/status');
     // Confirm that both messages and summaries will be displayed on status
     // report when there multiple messages.
-    $this->assertErrors([$expected_results['1:errors']]);
-    $this->assertWarnings([$expected_results['1:warnings']]);
+    $this->assertErrors([$expected_results['error']]);
+    $this->assertWarnings([$expected_results['warning']]);
 
     $key_value->delete('readiness_validation_last_run');
-    $expected_results = $this->testResults['checker_1']['2 warnings'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->drupalGet('admin/reports/status');
     $assert->pageTextContainsOnce('Update readiness checks');
@@ -168,7 +173,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $this->assertWarnings($expected_results);
 
     $key_value->delete('readiness_validation_last_run');
-    $expected_results = $this->testResults['checker_1']['1 warning'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->drupalGet('admin/reports/status');
     $assert->pageTextContainsOnce('Update readiness checks');
@@ -197,7 +202,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->testResults['checker_1']['1 error'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     // @todo Change this to use ::delayRequestTime() to simulate running cron
     //   after a 24 wait instead of directly deleting 'readiness_validation_last_run'
@@ -220,7 +225,10 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $assert->addressEquals('admin/structure');
     $assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]);
 
-    $expected_results = $this->testResults['checker_1']['1 error 1 warning'];
+    $expected_results = [
+      '1 error' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR),
+      '1 warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING),
+    ];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     // Confirm a new message is displayed if the cron is run after an hour.
     $this->delayRequestTime();
@@ -229,25 +237,28 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $assert->pageTextContainsOnce(static::$errorsExplanation);
     // Confirm on admin pages that a single error will be displayed instead of a
     // summary.
-    $this->assertSame(SystemManager::REQUIREMENT_ERROR, $expected_results['1:error']->getSeverity());
-    $assert->pageTextContainsOnce($expected_results['1:error']->getMessages()[0]);
-    $assert->pageTextNotContains($expected_results['1:error']->getSummary());
+    $this->assertSame(SystemManager::REQUIREMENT_ERROR, $expected_results['1 error']->getSeverity());
+    $assert->pageTextContainsOnce($expected_results['1 error']->getMessages()[0]);
+    $assert->pageTextNotContains($expected_results['1 error']->getSummary());
     // Warnings are not displayed on admin pages if there are any errors.
-    $this->assertSame(SystemManager::REQUIREMENT_WARNING, $expected_results['1:warning']->getSeverity());
-    $assert->pageTextNotContains($expected_results['1:warning']->getMessages()[0]);
-    $assert->pageTextNotContains($expected_results['1:warning']->getSummary());
+    $this->assertSame(SystemManager::REQUIREMENT_WARNING, $expected_results['1 warning']->getSeverity());
+    $assert->pageTextNotContains($expected_results['1 warning']->getMessages()[0]);
+    $assert->pageTextNotContains($expected_results['1 warning']->getSummary());
 
     // Confirm that if cron runs less than hour after it previously ran it will
     // not run the checkers again.
-    $unexpected_results = $this->testResults['checker_1']['2 errors 2 warnings'];
+    $unexpected_results = [
+      '2 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2),
+      '2 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2),
+    ];
     TestSubscriber1::setTestResult($unexpected_results, ReadinessCheckEvent::class);
     $this->delayRequestTime(30);
     $this->cronRun();
     $this->drupalGet('admin/structure');
-    $assert->pageTextNotContains($unexpected_results['1:errors']->getSummary());
-    $assert->pageTextContainsOnce($expected_results['1:error']->getMessages()[0]);
-    $assert->pageTextNotContains($unexpected_results['1:warnings']->getSummary());
-    $assert->pageTextNotContains($expected_results['1:warning']->getMessages()[0]);
+    $assert->pageTextNotContains($unexpected_results['2 errors']->getSummary());
+    $assert->pageTextContainsOnce($expected_results['1 error']->getMessages()[0]);
+    $assert->pageTextNotContains($unexpected_results['2 warnings']->getSummary());
+    $assert->pageTextNotContains($expected_results['1 warning']->getMessages()[0]);
 
     // Confirm that is if cron is run over an hour after the checkers were
     // previously run the checkers will be run again.
@@ -257,18 +268,18 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalGet('admin/structure');
     // Confirm on admin pages only the error summary will be displayed if there
     // is more than 1 error.
-    $this->assertSame(SystemManager::REQUIREMENT_ERROR, $expected_results['1:errors']->getSeverity());
-    $assert->pageTextNotContains($expected_results['1:errors']->getMessages()[0]);
-    $assert->pageTextNotContains($expected_results['1:errors']->getMessages()[1]);
-    $assert->pageTextContainsOnce($expected_results['1:errors']->getSummary());
+    $this->assertSame(SystemManager::REQUIREMENT_ERROR, $expected_results['2 errors']->getSeverity());
+    $assert->pageTextNotContains($expected_results['2 errors']->getMessages()[0]);
+    $assert->pageTextNotContains($expected_results['2 errors']->getMessages()[1]);
+    $assert->pageTextContainsOnce($expected_results['2 errors']->getSummary());
     $assert->pageTextContainsOnce(static::$errorsExplanation);
     // Warnings are not displayed on admin pages if there are any errors.
-    $this->assertSame(SystemManager::REQUIREMENT_WARNING, $expected_results['1:warnings']->getSeverity());
-    $assert->pageTextNotContains($expected_results['1:warnings']->getMessages()[0]);
-    $assert->pageTextNotContains($expected_results['1:warnings']->getMessages()[1]);
-    $assert->pageTextNotContains($expected_results['1:warnings']->getSummary());
+    $this->assertSame(SystemManager::REQUIREMENT_WARNING, $expected_results['2 warnings']->getSeverity());
+    $assert->pageTextNotContains($expected_results['2 warnings']->getMessages()[0]);
+    $assert->pageTextNotContains($expected_results['2 warnings']->getMessages()[1]);
+    $assert->pageTextNotContains($expected_results['2 warnings']->getSummary());
 
-    $expected_results = $this->testResults['checker_1']['2 warnings'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->delayRequestTime();
     $this->cronRun();
@@ -282,7 +293,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $assert->pageTextContainsOnce(static::$warningsExplanation);
     $assert->pageTextContainsOnce($expected_results[0]->getSummary());
 
-    $expected_results = $this->testResults['checker_1']['1 warning'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->delayRequestTime();
     $this->cronRun();
@@ -321,7 +332,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalGet('admin/reports/status');
     $this->assertNoErrors(TRUE);
 
-    $expected_results = $this->testResults['checker_1']['1 error'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber2::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->container->get('module_installer')->install(['automatic_updates_test2']);
     $this->drupalGet('admin/structure');
@@ -330,7 +341,10 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     // Confirm that installing a module runs the checkers, even if the new
     // module does not provide any validators.
     $previous_results = $expected_results;
-    $expected_results = $this->testResults['checker_1']['2 errors 2 warnings'];
+    $expected_results = [
+      '2 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2),
+      '2 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2),
+    ];
     TestSubscriber2::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->container->get('module_installer')->install(['help']);
     // Check for messages on 'admin/structure' instead of the status report,
@@ -338,8 +352,8 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalGet('admin/structure');
     // Confirm that new checker messages are displayed.
     $assert->pageTextNotContains($previous_results[0]->getMessages()[0]);
-    $assert->pageTextNotContains($expected_results['1:errors']->getMessages()[0]);
-    $assert->pageTextContainsOnce($expected_results['1:errors']->getSummary());
+    $assert->pageTextNotContains($expected_results['2 errors']->getMessages()[0]);
+    $assert->pageTextContainsOnce($expected_results['2 errors']->getSummary());
   }
 
   /**
@@ -349,9 +363,9 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $assert = $this->assertSession();
     $this->drupalLogin($this->checkerRunnerUser);
 
-    $expected_results_1 = $this->testResults['checker_1']['1 error'];
+    $expected_results_1 = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($expected_results_1, ReadinessCheckEvent::class);
-    $expected_results_2 = $this->testResults['checker_2']['1 error'];
+    $expected_results_2 = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber2::setTestResult($expected_results_2, ReadinessCheckEvent::class);
     $this->container->get('module_installer')->install([
       'automatic_updates',
@@ -392,7 +406,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
     $this->setCoreVersion('9.8.0');
 
     // Flag a validation error, which will be displayed in the messages area.
-    $results = $this->testResults['checker_1']['1 error'];
+    $results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($results, ReadinessCheckEvent::class);
     $message = $results[0]->getMessages()[0];
 
diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php
index b09ddf9534..d669f7f9b9 100644
--- a/tests/src/Functional/UpdaterFormTest.php
+++ b/tests/src/Functional/UpdaterFormTest.php
@@ -11,6 +11,7 @@ use Drupal\package_manager\Event\PreCreateEvent;
 use Drupal\package_manager\ValidationResult;
 use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
 use Drupal\package_manager_bypass\Stager;
+use Drupal\system\SystemManager;
 use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
 use Drupal\Tests\package_manager\Traits\PackageManagerBypassTestTrait;
 
@@ -239,8 +240,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.
-    $this->createTestValidationResults();
-    $expected_results = [$this->testResults['checker_1']['2 errors 2 warnings']['1:errors']];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
 
     // If a validator raises an error during readiness checking, the form should
@@ -412,8 +412,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
 
     // If a legitimate error is raised during pre-apply, we should be able to
     // delete the staged update right away.
-    $this->createTestValidationResults();
-    $results = $this->testResults['checker_1']['1 error'];
+    $results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($results, PreApplyEvent::class);
     $page->pressButton('Update to 9.8.1');
     $this->checkForMetaRefresh();
@@ -458,8 +457,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
 
     // Flag a warning, which will not block the update but should be displayed
     // on the updater form.
-    $this->createTestValidationResults();
-    $expected_results = $this->testResults['checker_1']['1 warning'];
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $messages = reset($expected_results)->getMessages();
 
diff --git a/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php b/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php
index 7766e911d7..f8bc8b8dfc 100644
--- a/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php
+++ b/tests/src/Kernel/ReadinessValidation/ReadinessValidationManagerTest.php
@@ -33,7 +33,6 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
     $this->setCoreVersion('9.8.2');
     $this->installEntitySchema('user');
     $this->installSchema('user', ['users_data']);
-    $this->createTestValidationResults();
   }
 
   /**
@@ -42,14 +41,11 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
   public function testGetResults(): void {
     $this->enableModules(['automatic_updates', 'automatic_updates_test2']);
     $this->assertCheckerResultsFromManager([], TRUE);
-
-    $expected_results = [
-      array_pop($this->testResults['checker_1']),
-      array_pop($this->testResults['checker_2']),
-    ];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
-    TestSubscriber2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
-    $expected_results_all = array_merge($expected_results[0], $expected_results[1]);
+    $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);
+    $expected_results_all = array_merge($checker_1_expected, $checker_2_expected);
     $this->assertCheckerResultsFromManager($expected_results_all, TRUE);
 
     // Define a constant flag that will cause the readiness checker
@@ -65,25 +61,29 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
     $expected_results_all_reversed = array_reverse($expected_results_all);
     $this->assertCheckerResultsFromManager($expected_results_all_reversed, TRUE);
 
-    $expected_results = [
-      $this->testResults['checker_1']['2 errors 2 warnings'],
-      $this->testResults['checker_2']['2 errors 2 warnings'],
+    $checker_1_expected = [
+      'checker 1 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR),
+      'checker 1 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING),
     ];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
-    TestSubscriber2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
-    $expected_results_all = array_merge($expected_results[1], $expected_results[0]);
+    $checker_2_expected = [
+      '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);
+    $expected_results_all = array_merge($checker_2_expected, $checker_1_expected);
     $this->assertCheckerResultsFromManager($expected_results_all, TRUE);
 
     // Confirm that filtering by severity works.
     $warnings_only_results = [
-      $expected_results[1]['2:warnings'],
-      $expected_results[0]['1:warnings'],
+      $checker_2_expected['checker 2 warnings'],
+      $checker_1_expected['checker 1 warnings'],
     ];
     $this->assertCheckerResultsFromManager($warnings_only_results, FALSE, SystemManager::REQUIREMENT_WARNING);
 
     $errors_only_results = [
-      $expected_results[1]['2:errors'],
-      $expected_results[0]['1:errors'],
+      $checker_2_expected['checker 2 errors'],
+      $checker_1_expected['checker 1 errors'],
     ];
     $this->assertCheckerResultsFromManager($errors_only_results, FALSE, SystemManager::REQUIREMENT_ERROR);
   }
@@ -92,34 +92,30 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
    * Tests that the manager is run after modules are installed.
    */
   public function testRunOnInstall(): void {
-    $expected_results = [array_pop($this->testResults['checker_1'])];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
+    $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
+    TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class);
     // Confirm that messages from an existing module are displayed when
     // 'automatic_updates' is installed.
     $this->container->get('module_installer')->install(['automatic_updates']);
-    $this->assertCheckerResultsFromManager($expected_results[0]);
+    $this->assertCheckerResultsFromManager($checker_1_results);
 
     // Confirm that the checkers are run when a module that provides a readiness
     // checker is installed.
-    $expected_results = [
-      array_pop($this->testResults['checker_1']),
-      array_pop($this->testResults['checker_2']),
-    ];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
-    TestSubscriber2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
+    $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);
     $this->container->get('module_installer')->install(['automatic_updates_test2']);
-    $expected_results_all = array_merge($expected_results[0], $expected_results[1]);
+    $expected_results_all = array_merge($checker_1_results, $checker_2_results);
     $this->assertCheckerResultsFromManager($expected_results_all);
 
     // Confirm that the checkers are run when a module that does not provide a
     // readiness checker is installed.
-    $expected_results = [
-      array_pop($this->testResults['checker_1']),
-      array_pop($this->testResults['checker_2']),
-    ];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
-    TestSubscriber2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
-    $expected_results_all = array_merge($expected_results[0], $expected_results[1]);
+    $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);
+    $expected_results_all = array_merge($checker_1_results, $checker_2_results);
     $this->container->get('module_installer')->install(['help']);
     $this->assertCheckerResultsFromManager($expected_results_all);
   }
@@ -128,36 +124,31 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
    * Tests that the manager is run after modules are uninstalled.
    */
   public function testRunOnUninstall(): void {
-    $expected_results = [
-      array_pop($this->testResults['checker_1']),
-      array_pop($this->testResults['checker_2']),
-    ];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
-    TestSubscriber2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
+    $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);
     // 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']);
-    $expected_results_all = array_merge($expected_results[0], $expected_results[1]);
+    $expected_results_all = array_merge($checker_1_results, $checker_2_results);
     $this->assertCheckerResultsFromManager($expected_results_all);
 
     // Confirm that the checkers are run when a module that provides a readiness
     // checker is uninstalled.
-    $expected_results = [
-      array_pop($this->testResults['checker_1']),
-    ];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
-    TestSubscriber2::setTestResult(array_pop($this->testResults['checker_2']), ReadinessCheckEvent::class);
+    $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);
     $this->container->get('module_installer')->uninstall(['automatic_updates_test2']);
-    $this->assertCheckerResultsFromManager($expected_results[0]);
+    $this->assertCheckerResultsFromManager($checker_1_results);
 
     // Confirm that the checkers are run when a module that does not provide a
     // readiness checker is uninstalled.
-    $expected_results = [
-      array_pop($this->testResults['checker_1']),
-    ];
-    TestSubscriber1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
+    $checker_1_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
+    TestSubscriber1::setTestResult($checker_1_results, ReadinessCheckEvent::class);
     $this->container->get('module_installer')->uninstall(['help']);
-    $this->assertCheckerResultsFromManager($expected_results[0]);
+    $this->assertCheckerResultsFromManager($checker_1_results);
   }
 
   /**
@@ -165,12 +156,12 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
    * @covers ::clearStoredResults
    */
   public function testRunIfNeeded(): void {
-    $expected_results = array_pop($this->testResults['checker_1']);
+    $expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($expected_results, ReadinessCheckEvent::class);
     $this->container->get('module_installer')->install(['automatic_updates', 'automatic_updates_test2']);
     $this->assertCheckerResultsFromManager($expected_results);
 
-    $unexpected_results = array_pop($this->testResults['checker_1']);
+    $unexpected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($unexpected_results, ReadinessCheckEvent::class);
     $manager = $this->container->get('automatic_updates.readiness_validation_manager');
     // Confirm that the new results will not be returned because the checkers
@@ -186,7 +177,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
     $this->assertCheckerResultsFromManager($expected_results);
 
     // Confirm that the results are the same after rebuilding the container.
-    $unexpected_results = array_pop($this->testResults['checker_1']);
+    $unexpected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($unexpected_results, ReadinessCheckEvent::class);
     /** @var \Drupal\Core\DrupalKernel $kernel */
     $kernel = $this->container->get('kernel');
@@ -225,7 +216,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
 
     // The readiness checker should raise a warning, so that the update is not
     // blocked or aborted.
-    $results = $this->testResults['checker_1']['1 warning'];
+    $results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)];
     TestSubscriber1::setTestResult($results, ReadinessCheckEvent::class);
 
     // Ensure that the validation manager collects the warning.
@@ -267,7 +258,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
   public function testStoredResultsClearedOnConfigChanges(): void {
     $this->enableModules(['automatic_updates']);
 
-    $results = $this->testResults['checker_1']['1 error'];
+    $results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
     TestSubscriber1::setTestResult($results, ReadinessCheckEvent::class);
     $this->assertCheckerResultsFromManager($results, TRUE);
     // The results should be stored.
diff --git a/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php b/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php
index 599f04e8af..5a514f542e 100644
--- a/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php
+++ b/tests/src/Kernel/ReadinessValidation/VersionPolicyValidatorTest.php
@@ -48,7 +48,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.1-security.xml",
         [CronUpdater::DISABLED, CronUpdater::SECURITY, CronUpdater::ALL],
         [
-          $this->createValidationResult('9.8.0-dev', NULL, [
+          $this->createVersionPolicyValidationResult('9.8.0-dev', NULL, [
             'Drupal cannot be automatically updated from the installed version, 9.8.0-dev, because automatic updates from a dev version to any other version are not supported.',
           ]),
         ],
@@ -66,7 +66,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.1-security.xml",
         [CronUpdater::SECURITY, CronUpdater::ALL],
         [
-          $this->createValidationResult('9.8.0-alpha1', NULL, [
+          $this->createVersionPolicyValidationResult('9.8.0-alpha1', NULL, [
             'Drupal cannot be automatically updated during cron from its current version, 9.8.0-alpha1, because it is not a stable version.',
           ]),
         ],
@@ -82,7 +82,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.1-security.xml",
         [CronUpdater::SECURITY, CronUpdater::ALL],
         [
-          $this->createValidationResult('9.8.0-beta2', NULL, [
+          $this->createVersionPolicyValidationResult('9.8.0-beta2', NULL, [
             'Drupal cannot be automatically updated during cron from its current version, 9.8.0-beta2, because it is not a stable version.',
           ]),
         ],
@@ -98,7 +98,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.1-security.xml",
         [CronUpdater::SECURITY, CronUpdater::ALL],
         [
-          $this->createValidationResult('9.8.0-rc3', NULL, [
+          $this->createVersionPolicyValidationResult('9.8.0-rc3', NULL, [
             'Drupal cannot be automatically updated during cron from its current version, 9.8.0-rc3, because it is not a stable version.',
           ]),
         ],
@@ -132,7 +132,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.1-security.xml",
         [CronUpdater::SECURITY, CronUpdater::ALL],
         [
-          $this->createValidationResult('9.7.1', NULL, [
+          $this->createVersionPolicyValidationResult('9.7.1', NULL, [
             'The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.',
             'See the <a href="/admin/reports/updates">available updates page</a> for available updates.',
           ]),
@@ -143,7 +143,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.1-security.xml",
         [CronUpdater::SECURITY, CronUpdater::ALL],
         [
-          $this->createValidationResult('9.7.1', NULL, [
+          $this->createVersionPolicyValidationResult('9.7.1', NULL, [
             'The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.',
             'Use the <a href="/admin/modules/automatic-update">update form</a> to update to a supported version.',
           ]),
@@ -202,7 +202,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.1-security.xml",
         ['drupal' => '9.8.1'],
         [
-          $this->createValidationResult('9.8.0-dev', '9.8.1', [
+          $this->createVersionPolicyValidationResult('9.8.0-dev', '9.8.1', [
             'Drupal cannot be automatically updated from the installed version, 9.8.0-dev, because automatic updates from a dev version to any other version are not supported.',
           ]),
         ],
@@ -214,7 +214,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.2.xml",
         ['drupal' => '9.8.0'],
         [
-          $this->createValidationResult('9.8.1', '9.8.0', [
+          $this->createVersionPolicyValidationResult('9.8.1', '9.8.0', [
             'Update version 9.8.0 is lower than 9.8.1, downgrading is not supported.',
           ]),
         ],
@@ -224,7 +224,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.2.xml",
         ['drupal' => '9.8.2'],
         [
-          $this->createValidationResult('8.9.1', '9.8.2', [
+          $this->createVersionPolicyValidationResult('8.9.1', '9.8.2', [
             'Drupal cannot be automatically updated from 8.9.1 to 9.8.2 because automatic updates from one major version to another are not supported.',
           ]),
         ],
@@ -234,7 +234,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.2-unsupported_unpublished.xml",
         ['drupal' => '9.8.1'],
         [
-          $this->createValidationResult('9.8.0', '9.8.1', [
+          $this->createVersionPolicyValidationResult('9.8.0', '9.8.1', [
             'Cannot update Drupal core to 9.8.1 because it is not in the list of installable releases.',
           ]),
         ],
@@ -255,7 +255,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
         "$metadata_dir/drupal.9.8.2.xml",
         ['drupal' => '9.8.2'],
         [
-          $this->createValidationResult('9.7.9', '9.8.2', [
+          $this->createVersionPolicyValidationResult('9.7.9', '9.8.2', [
             'Drupal cannot be automatically updated from 9.7.9 to 9.8.2 because automatic updates from one minor version to another are not supported.',
           ]),
         ],
@@ -320,7 +320,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
   }
 
   /**
-   * Creates an expected validation result.
+   * Creates an expected validation result from the version policy validator.
    *
    * Results returned from VersionPolicyValidator are always summarized in the
    * same way, so this method ensures that expected validation results are
@@ -336,7 +336,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase {
    * @return \Drupal\package_manager\ValidationResult
    *   A validation error object with the appropriate summary.
    */
-  private function createValidationResult(string $installed_version, ?string $target_version, array $messages): ValidationResult {
+  private function createVersionPolicyValidationResult(string $installed_version, ?string $target_version, array $messages): ValidationResult {
     if ($target_version) {
       $summary = t('Updating from Drupal @installed_version to @target_version is not allowed.', [
         '@installed_version' => $installed_version,
diff --git a/tests/src/Traits/ValidationTestTrait.php b/tests/src/Traits/ValidationTestTrait.php
index 592d24b39a..a08458f379 100644
--- a/tests/src/Traits/ValidationTestTrait.php
+++ b/tests/src/Traits/ValidationTestTrait.php
@@ -3,7 +3,7 @@
 namespace Drupal\Tests\automatic_updates\Traits;
 
 use Drupal\package_manager\ValidationResult;
-
+use Drupal\system\SystemManager;
 use Drupal\Tests\package_manager\Traits\ValidationTestTrait as PackageManagerValidationTestTrait;
 
 /**
@@ -28,67 +28,34 @@ trait ValidationTestTrait {
   protected static $warningsExplanation = 'Your site does not pass some readiness checks for automatic updates. Depending on the nature of the failures, it might affect the eligibility for automatic updates.';
 
   /**
-   * Test validation results.
+   * Creates a unique validation test result.
+   *
+   * @param int $severity
+   *   The severity. Should be one of the SystemManager::REQUIREMENT_*
+   *   constants.
+   * @param int $message_count
+   *   (optional) The number of messages. Defaults to 1.
    *
-   * @var \Drupal\package_manager\ValidationResult[][][]
+   * @return \Drupal\package_manager\ValidationResult
+   *   The validation test result.
    */
-  protected $testResults;
+  protected function createValidationResult(int $severity, int $message_count = 1): ValidationResult {
+    $this->assertNotEmpty($message_count);
+    $messages = [];
+    $random = $this->randomMachineName(64);
+    for ($i = 0; $i < $message_count; $i++) {
+      $messages[] = "Message $i $random";
+    }
+    $summary = t('Summary @random', ['@random' => $random]);
+    switch ($severity) {
+      case SystemManager::REQUIREMENT_ERROR:
+        return ValidationResult::createError($messages, $summary);
 
-  /**
-   * Creates ValidationResult objects to be used in tests.
-   */
-  protected function createTestValidationResults(): void {
-    // Set up various validation results for the test checkers.
-    foreach ([1, 2] as $listener_number) {
-      // Set test validation results.
-      $this->testResults["checker_$listener_number"]['1 error'] = [
-        ValidationResult::createError(
-          [t("$listener_number:OMG 🚒. Your server is on 🔥!")],
-          t("$listener_number:Summary: 🔥")
-        ),
-      ];
-      $this->testResults["checker_$listener_number"]['1 error 1 warning'] = [
-        "$listener_number:error" => ValidationResult::createError(
-          [t("$listener_number:OMG 🔌. Some one unplugged the server! How is this site even running?")],
-          t("$listener_number:Summary: 🔥")
-        ),
-        "$listener_number:warning" => ValidationResult::createWarning(
-          [t("$listener_number:It looks like it going to rain and your server is outside.")],
-          t("$listener_number:Warnings summary not displayed because only 1 warning message.")
-        ),
-      ];
-      $this->testResults["checker_$listener_number"]['2 errors 2 warnings'] = [
-        "$listener_number:errors" => ValidationResult::createError(
-          [
-            t("$listener_number:😬Your server is in a cloud, a literal cloud!☁️."),
-            t("$listener_number:😂PHP only has 32k memory."),
-          ],
-          t("$listener_number:Errors summary displayed because more than 1 error message")
-        ),
-        "$listener_number:warnings" => ValidationResult::createWarning(
-          [
-            t("$listener_number:Your server is a smart fridge. Will this work?"),
-            t("$listener_number:Your server case is duct tape!"),
-          ],
-          t("$listener_number:Warnings summary displayed because more than 1 warning message.")
-        ),
+      case SystemManager::REQUIREMENT_WARNING:
+        return ValidationResult::createWarning($messages, $summary);
 
-      ];
-      $this->testResults["checker_$listener_number"]['2 warnings'] = [
-        ValidationResult::createWarning(
-          [
-            t("$listener_number:The universe could collapse in on itself in the next second, in which case automatic updates will not run."),
-            t("$listener_number:An asteroid could hit your server farm, which would also stop automatic updates from running."),
-          ],
-          t("$listener_number:Warnings summary displayed because more than 1 warning message.")
-        ),
-      ];
-      $this->testResults["checker_$listener_number"]['1 warning'] = [
-        ValidationResult::createWarning(
-          [t("$listener_number:This is your one and only warning. You have been warned.")],
-          t("$listener_number:No need for this summary with only 1 warning.")
-        ),
-      ];
+      default:
+        throw new \InvalidArgumentException("$severity is an invalid value for \$severity; it must be SystemManager::REQUIREMENT_ERROR or SystemManager::REQUIREMENT_WARNING.");
     }
   }
 
-- 
GitLab