From e939f093c26d26eeee55f7330b2b9cdaf87618a2 Mon Sep 17 00:00:00 2001
From: Ted Bowman <41201-tedbow@users.noreply.drupalcode.org>
Date: Fri, 26 May 2023 01:15:15 +0000
Subject: [PATCH] Issue #3362746 by tedbow: fix 10.0.x phpstan errors

---
 .../tests/src/Build/ModuleUpdateTest.php      | 13 +++++-
 .../src/Build/TemplateProjectTestBase.php     | 40 ++++++++++++++++++
 .../Kernel/PackageManagerKernelTestBase.php   |  2 +
 tests/src/Build/CoreUpdateTest.php            | 41 -------------------
 4 files changed, 54 insertions(+), 42 deletions(-)

diff --git a/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php b/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php
index c3b642998d..dcbd01d1f1 100644
--- a/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php
+++ b/automatic_updates_extensions/tests/src/Build/ModuleUpdateTest.php
@@ -24,7 +24,7 @@ class ModuleUpdateTest extends UpdateTestBase {
   protected function createTestProject(string $template): void {
     parent::createTestProject($template);
     $this->setReleaseMetadata([
-      'drupal' => __DIR__ . '/../../../../package_manager/tests/fixtures/release-history/drupal.9.8.1-security.xml',
+      'drupal' => __DIR__ . '/../../../../package_manager/tests/fixtures/release-history/drupal.9.8.2.xml',
       'alpha'  => __DIR__ . '/../../fixtures/release-history/alpha.1.1.0.xml',
       'new_module' => __DIR__ . '/../../fixtures/release-history/new_module.1.1.0.xml',
     ]);
@@ -133,6 +133,17 @@ END;
     $this->assertModuleVersion('alpha', '1.1.0');
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function copyCodebase(\Iterator $iterator = NULL, $working_dir = NULL): void {
+    parent::copyCodebase($iterator, $working_dir);
+
+    // Ensure that we will install Drupal 9.8.0 (a fake version that should
+    // never exist in real life) initially.
+    $this->setUpstreamCoreVersion('9.8.0');
+  }
+
   /**
    * Assert a project version is on the Available Updates page.
    *
diff --git a/package_manager/tests/src/Build/TemplateProjectTestBase.php b/package_manager/tests/src/Build/TemplateProjectTestBase.php
index 62f4bbeac7..9cbc66d733 100644
--- a/package_manager/tests/src/Build/TemplateProjectTestBase.php
+++ b/package_manager/tests/src/Build/TemplateProjectTestBase.php
@@ -81,6 +81,46 @@ abstract class TemplateProjectTestBase extends QuickStartTestBase {
     return parent::getCodebaseFinder()->notPath('#^core/node_modules#');
   }
 
+  /**
+   * Sets the version of Drupal core to which the test site will be updated.
+   *
+   * @param string $version
+   *   The Drupal core version to set.
+   */
+  protected function setUpstreamCoreVersion(string $version): void {
+    $workspace_dir = $this->getWorkspaceDirectory();
+
+    // Loop through core's metapackages and plugins, and alter them as needed.
+    $packages = str_replace("$workspace_dir/", '', $this->getCorePackages());
+    foreach ($packages as $path) {
+      // Assign the new upstream version.
+      $this->runComposer("composer config version $version", $path);
+
+      // If this package requires Drupal core (e.g., drupal/core-recommended),
+      // make it require the new upstream version.
+      $info = $this->runComposer('composer info --self --format json', $path, TRUE);
+      if (isset($info['requires']['drupal/core'])) {
+        $this->runComposer("composer require --no-update drupal/core:$version", $path);
+      }
+    }
+
+    // Change the \Drupal::VERSION constant and put placeholder text in the
+    // README so we can ensure that we really updated to the correct version. We
+    // also change the default site configuration files so we can ensure that
+    // these are updated as well, despite `sites/default` being write-protected.
+    // @see ::assertUpdateSuccessful()
+    // @see ::createTestProject()
+    Composer::setDrupalVersion($workspace_dir, $version);
+    file_put_contents("$workspace_dir/core/README.txt", "Placeholder for Drupal core $version.");
+
+    foreach (['default.settings.php', 'default.services.yml'] as $file) {
+      $file = fopen("$workspace_dir/core/assets/scaffold/files/$file", 'a');
+      $this->assertIsResource($file);
+      fwrite($file, "# This is part of Drupal $version.\n");
+      fclose($file);
+    }
+  }
+
   /**
    * Returns the full path to the test site's document root.
    *
diff --git a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php
index 4d222646e7..909ab4017b 100644
--- a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php
+++ b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php
@@ -92,6 +92,7 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase {
    * The Symfony filesystem class.
    *
    * @var \Symfony\Component\Filesystem\Filesystem
+   * @phpstan-ignore-next-line
    */
   private readonly Filesystem $fileSystem;
 
@@ -101,6 +102,7 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase {
    * @var \ColinODell\PsrTestLogger\TestLogger
    *
    * @see ::tearDown()
+   * @phpstan-ignore-next-line
    */
   protected readonly TestLogger $failureLogger;
 
diff --git a/tests/src/Build/CoreUpdateTest.php b/tests/src/Build/CoreUpdateTest.php
index 5629af9e06..f362e4b58e 100644
--- a/tests/src/Build/CoreUpdateTest.php
+++ b/tests/src/Build/CoreUpdateTest.php
@@ -8,7 +8,6 @@ use Behat\Mink\Element\DocumentElement;
 use Drupal\automatic_updates\DrushUpdateStage;
 use Drupal\automatic_updates\CronUpdateStage;
 use Drupal\automatic_updates\UpdateStage;
-use Drupal\Composer\Composer;
 use Drupal\package_manager\Event\PostApplyEvent;
 use Drupal\package_manager\Event\PostCreateEvent;
 use Drupal\package_manager\Event\PostDestroyEvent;
@@ -267,46 +266,6 @@ class CoreUpdateTest extends UpdateTestBase {
     }
   }
 
-  /**
-   * Sets the version of Drupal core to which the test site will be updated.
-   *
-   * @param string $version
-   *   The Drupal core version to set.
-   */
-  private function setUpstreamCoreVersion(string $version): void {
-    $workspace_dir = $this->getWorkspaceDirectory();
-
-    // Loop through core's metapackages and plugins, and alter them as needed.
-    $packages = str_replace("$workspace_dir/", '', $this->getCorePackages());
-    foreach ($packages as $path) {
-      // Assign the new upstream version.
-      $this->runComposer("composer config version $version", $path);
-
-      // If this package requires Drupal core (e.g., drupal/core-recommended),
-      // make it require the new upstream version.
-      $info = $this->runComposer('composer info --self --format json', $path, TRUE);
-      if (isset($info['requires']['drupal/core'])) {
-        $this->runComposer("composer require --no-update drupal/core:$version", $path);
-      }
-    }
-
-    // Change the \Drupal::VERSION constant and put placeholder text in the
-    // README so we can ensure that we really updated to the correct version. We
-    // also change the default site configuration files so we can ensure that
-    // these are updated as well, despite `sites/default` being write-protected.
-    // @see ::assertUpdateSuccessful()
-    // @see ::createTestProject()
-    Composer::setDrupalVersion($workspace_dir, $version);
-    file_put_contents("$workspace_dir/core/README.txt", "Placeholder for Drupal core $version.");
-
-    foreach (['default.settings.php', 'default.services.yml'] as $file) {
-      $file = fopen("$workspace_dir/core/assets/scaffold/files/$file", 'a');
-      $this->assertIsResource($file);
-      fwrite($file, "# This is part of Drupal $version.\n");
-      fclose($file);
-    }
-  }
-
   /**
    * Asserts that a specific version of Drupal core is running.
    *
-- 
GitLab