From 52f22acd9a05e1fa58f42f9839b20a83ca5d6645 Mon Sep 17 00:00:00 2001
From: "kunal.sachdev" <kunal.sachdev@3685163.no-reply.drupal.org>
Date: Fri, 22 Jul 2022 17:34:03 +0000
Subject: [PATCH] Issue #3295965 by kunal.sachdev, tedbow, phenaproxima: Add
 validation that $projects cannot be an empty array in
 \Drupal\automatic_updates_extensions\ExtensionUpdater::begin

---
 automatic_updates_extensions/src/ExtensionUpdater.php    | 5 ++++-
 .../tests/src/Kernel/ExtensionUpdaterTest.php            | 9 +++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/automatic_updates_extensions/src/ExtensionUpdater.php b/automatic_updates_extensions/src/ExtensionUpdater.php
index 7ee83c8b34..4948ff6133 100644
--- a/automatic_updates_extensions/src/ExtensionUpdater.php
+++ b/automatic_updates_extensions/src/ExtensionUpdater.php
@@ -27,9 +27,12 @@ class ExtensionUpdater extends Stage {
    *   The unique ID of the stage.
    *
    * @throws \InvalidArgumentException
-   *   Thrown if no project version for Drupal core is provided.
+   *   Thrown if no project version is provided.
    */
   public function begin(array $project_versions): string {
+    if (empty($project_versions)) {
+      throw new \InvalidArgumentException("No projects to begin the update");
+    }
     $composer = $this->getActiveComposer();
     $package_versions = [
       'production' => [],
diff --git a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php
index d863afa1b1..61f0845de0 100644
--- a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php
+++ b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php
@@ -114,4 +114,13 @@ class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase {
     }
   }
 
+  /**
+   * Tests that an exception is thrown when calling begin() with no projects.
+   */
+  public function testNoProjectsInBegin(): void {
+    $this->expectException('InvalidArgumentException');
+    $this->expectExceptionMessage('No projects to begin the update');
+    $this->container->get('automatic_updates_extensions.updater')->begin([]);
+  }
+
 }
-- 
GitLab