From 461eb14b7a08532c74134dbbea0c23bcaf607e82 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Mon, 6 Feb 2023 11:41:06 +0000
Subject: [PATCH] Issue #3326378 by Spokje: Fix PHPStan L1 error "Instantiated
 class Foo\Bar not found."

---
 .../FileTransfer/FileTransferTest.php         |  2 +-
 core/phpstan-baseline.neon                    | 25 -------------------
 .../Core/Test/BrowserTestBaseTest.php         |  2 ++
 .../Drupal/KernelTests/KernelTestBaseTest.php |  2 ++
 ...rowserMissingDependentModuleMethodTest.php |  2 +-
 .../BrowserMissingDependentModuleTest.php     |  2 +-
 ...KernelMissingDependentModuleMethodTest.php |  2 +-
 .../KernelMissingDependentModuleTest.php      |  2 +-
 8 files changed, 9 insertions(+), 30 deletions(-)

diff --git a/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php b/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php
index 6d5d6f41129f..7d6bd2c9d44d 100644
--- a/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php
+++ b/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php
@@ -53,7 +53,7 @@ public function _buildFakeModule() {
       $output = [];
       exec('rm -Rf ' . escapeshellarg($location), $output, $ret);
       if ($ret != 0) {
-        throw new Exception('Error removing fake module directory.');
+        throw new \Exception('Error removing fake module directory.');
       }
     }
 
diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index 9bcf254fe571..955f2987dd4b 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -2205,11 +2205,6 @@ parameters:
 			count: 1
 			path: modules/system/tests/modules/module_installer_config_test/src/Entity/TestConfigType.php
 
-		-
-			message: "#^Instantiated class Drupal\\\\Tests\\\\system\\\\Functional\\\\FileTransfer\\\\Exception not found\\.$#"
-			count: 1
-			path: modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php
-
 		-
 			message: "#^Access to an undefined property Drupal\\\\Tests\\\\system\\\\Functional\\\\FileTransfer\\\\TestFileTransfer\\:\\:\\$connection\\.$#"
 			count: 5
@@ -3090,16 +3085,6 @@ parameters:
 			count: 1
 			path: tests/Drupal/KernelTests/Core/TempStore/TempStoreDatabaseTest.php
 
-		-
-			message: "#^Instantiated class Drupal\\\\FunctionalTests\\\\BrowserMissingDependentModuleMethodTest not found\\.$#"
-			count: 1
-			path: tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
-
-		-
-			message: "#^Instantiated class Drupal\\\\FunctionalTests\\\\BrowserMissingDependentModuleTest not found\\.$#"
-			count: 1
-			path: tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
-
 		-
 			message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
 			count: 5
@@ -3110,16 +3095,6 @@ parameters:
 			count: 1
 			path: tests/Drupal/KernelTests/KernelTestBase.php
 
-		-
-			message: "#^Instantiated class Drupal\\\\KernelTests\\\\KernelMissingDependentModuleMethodTest not found\\.$#"
-			count: 1
-			path: tests/Drupal/KernelTests/KernelTestBaseTest.php
-
-		-
-			message: "#^Instantiated class Drupal\\\\KernelTests\\\\KernelMissingDependentModuleTest not found\\.$#"
-			count: 1
-			path: tests/Drupal/KernelTests/KernelTestBaseTest.php
-
 		-
 			message: "#^Call to an undefined method Drupal\\\\TestSite\\\\Commands\\\\TestSiteInstallCommand\\:\\:assertTrue\\(\\)\\.$#"
 			count: 1
diff --git a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
index de7f7ebea2d0..a9587313c74c 100644
--- a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
@@ -27,6 +27,7 @@ class BrowserTestBaseTest extends KernelTestBase {
   public function testMethodRequiresModule() {
     require __DIR__ . '/../../../../fixtures/BrowserMissingDependentModuleMethodTest.php';
 
+    // @phpstan-ignore-next-line
     $stub_test = new BrowserMissingDependentModuleMethodTest();
     // We have to setName() to the method name we're concerned with.
     $stub_test->setName('testRequiresModule');
@@ -54,6 +55,7 @@ public function testMethodRequiresModule() {
   public function testRequiresModule() {
     require __DIR__ . '/../../../../fixtures/BrowserMissingDependentModuleTest.php';
 
+    // @phpstan-ignore-next-line
     $stub_test = new BrowserMissingDependentModuleTest();
     // We have to setName() to the method name we're concerned with.
     $stub_test->setName('testRequiresModule');
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index fefc271f911f..1d651850879f 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -254,6 +254,7 @@ public function testLocalTimeZone() {
   public function testMethodRequiresModule() {
     require __DIR__ . '/../../fixtures/KernelMissingDependentModuleMethodTest.php';
 
+    // @phpstan-ignore-next-line
     $stub_test = new KernelMissingDependentModuleMethodTest();
     // We have to setName() to the method name we're concerned with.
     $stub_test->setName('testRequiresModule');
@@ -281,6 +282,7 @@ public function testMethodRequiresModule() {
   public function testRequiresModule() {
     require __DIR__ . '/../../fixtures/KernelMissingDependentModuleTest.php';
 
+    // @phpstan-ignore-next-line
     $stub_test = new KernelMissingDependentModuleTest();
     // We have to setName() to the method name we're concerned with.
     $stub_test->setName('testRequiresModule');
diff --git a/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
index 4a94a536919e..bbf56501e832 100644
--- a/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
+++ b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
@@ -10,7 +10,7 @@
  * This is a fixture class for
  * \Drupal\FunctionalTests\BrowserTestBaseTest::testMethodRequiresModule().
  *
- * This test class should not be discovered by run-tests.sh or phpunit.
+ * This test class should not be discovered by run-tests.sh, phpstan or phpunit.
  *
  * @group fixture
  */
diff --git a/core/tests/fixtures/BrowserMissingDependentModuleTest.php b/core/tests/fixtures/BrowserMissingDependentModuleTest.php
index 9650fc1b95cf..3a443746b176 100644
--- a/core/tests/fixtures/BrowserMissingDependentModuleTest.php
+++ b/core/tests/fixtures/BrowserMissingDependentModuleTest.php
@@ -10,7 +10,7 @@
  * This is a fixture class for
  * \Drupal\FunctionalTests\BrowserTestBaseTest::testRequiresModule().
  *
- * This test class should not be discovered by run-tests.sh or phpunit.
+ * This test class should not be discovered by run-tests.sh, phpstan or phpunit.
  *
  * @requires module module_does_not_exist
  * @group fixture
diff --git a/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
index 33dc79389f1b..80f69c32a9ee 100644
--- a/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
+++ b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
@@ -8,7 +8,7 @@
  * This is a fixture class for
  * \Drupal\KernelTests\KernelTestBaseTest::testRequiresModule().
  *
- * This test class should not be discovered by run-tests.sh or phpunit.
+ * This test class should not be discovered by run-tests.sh, phpstan or phpunit.
  *
  * @group fixture
  */
diff --git a/core/tests/fixtures/KernelMissingDependentModuleTest.php b/core/tests/fixtures/KernelMissingDependentModuleTest.php
index 3b8f316b2232..9fc372c03b58 100644
--- a/core/tests/fixtures/KernelMissingDependentModuleTest.php
+++ b/core/tests/fixtures/KernelMissingDependentModuleTest.php
@@ -8,7 +8,7 @@
  * This is a fixture class for
  * \Drupal\KernelTests\KernelTestBaseTest::testRequiresModule().
  *
- * This test class should not be discovered by run-tests.sh or phpunit.
+ * This test class should not be discovered by run-tests.sh, phpstan or phpunit.
  *
  * @requires module module_does_not_exist
  * @group fixture
-- 
GitLab