From acc33a1842efffdfcc202818d5e8cae5325bab9d Mon Sep 17 00:00:00 2001
From: phenaproxima <phenaproxima@205645.no-reply.drupal.org>
Date: Tue, 9 Nov 2021 17:50:44 +0000
Subject: [PATCH] Issue #3248523 by phenaproxima, tedbow: All validation kernel
 tests should be validating the same way

---
 .../no_core_requirements/vendor/.gitkeep      |  0
 .../CoreComposerValidatorTest.php             | 15 ++++-----------
 .../StagedProjectsValidatorTest.php           | 19 ++++++++++++-------
 3 files changed, 16 insertions(+), 18 deletions(-)
 create mode 100644 tests/fixtures/project_staged_validation/no_core_requirements/vendor/.gitkeep

diff --git a/tests/fixtures/project_staged_validation/no_core_requirements/vendor/.gitkeep b/tests/fixtures/project_staged_validation/no_core_requirements/vendor/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php b/tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php
index bc54f88e77..3a0fdb99dc 100644
--- a/tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php
+++ b/tests/src/Kernel/ReadinessValidation/CoreComposerValidatorTest.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation;
 
 use Drupal\package_manager\ValidationResult;
-use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\package_manager\PathLocator;
 use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase;
 
@@ -22,22 +21,16 @@ class CoreComposerValidatorTest extends AutomaticUpdatesKernelTestBase {
     'package_manager',
   ];
 
-  /**
-   * {@inheritdoc}
-   */
-  public function register(ContainerBuilder $container) {
-    parent::register($container);
-    // Disable validators which interfere with the validator under test.
-    $container->removeDefinition('automatic_updates.disk_space_validator');
-  }
-
   /**
    * Tests that an error is raised if core is not required in composer.json.
    */
   public function testCoreNotRequired(): void {
     // Point to a valid composer.json with no requirements.
+    $active_dir = __DIR__ . '/../../../fixtures/project_staged_validation/no_core_requirements';
     $locator = $this->prophesize(PathLocator::class);
-    $locator->getActiveDirectory()->willReturn(__DIR__ . '/../../../fixtures/project_staged_validation/no_core_requirements');
+    $locator->getActiveDirectory()->willReturn($active_dir);
+    $locator->getProjectRoot()->willReturn($active_dir);
+    $locator->getVendorDirectory()->willReturn($active_dir . '/vendor');
     $this->container->set('package_manager.path_locator', $locator->reveal());
 
     $error = ValidationResult::createError([
diff --git a/tests/src/Kernel/ReadinessValidation/StagedProjectsValidatorTest.php b/tests/src/Kernel/ReadinessValidation/StagedProjectsValidatorTest.php
index 82e0feed52..21d7a1d0b3 100644
--- a/tests/src/Kernel/ReadinessValidation/StagedProjectsValidatorTest.php
+++ b/tests/src/Kernel/ReadinessValidation/StagedProjectsValidatorTest.php
@@ -3,8 +3,8 @@
 namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation;
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\package_manager\Event\PreApplyEvent;
 use Drupal\package_manager\PathLocator;
+use Drupal\package_manager\StageException;
 use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase;
 
 /**
@@ -50,12 +50,17 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase {
     $locator->getStageDirectory()->willReturn($stage_dir);
     $this->container->set('package_manager.path_locator', $locator->reveal());
 
-    $event = new PreApplyEvent(
-      $this->container->get('automatic_updates.updater')
-    );
-
-    $this->container->get('event_dispatcher')->dispatch($event);
-    return $event->getResults();
+    // The staged projects validator only runs before staged updates are
+    // applied. Since the active and stage directories may not exist, we don't
+    // want to invoke the other stages of the update because they may raise
+    // errors that are outside of the scope of what we're testing here.
+    try {
+      $this->container->get('automatic_updates.updater')->apply();
+      return [];
+    }
+    catch (StageException $e) {
+      return $e->getResults();
+    }
   }
 
   /**
-- 
GitLab