From d0685981600721082a2ccb120f4893c47bfd1bc3 Mon Sep 17 00:00:00 2001
From: "kunal.sachdev" <kunal.sachdev@3685163.no-reply.drupal.org>
Date: Fri, 23 Sep 2022 16:13:27 +0000
Subject: [PATCH] Issue #3306163 by kunal.sachdev:  Also skip info.yml files in
 more test directories in DuplicateInfoFileValidator

---
 .../Validator/DuplicateInfoFileValidator.php  | 35 +++++++++++++++----
 .../Kernel/DuplicateInfoFileValidatorTest.php | 32 ++++++++++++++++-
 2 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/package_manager/src/Validator/DuplicateInfoFileValidator.php b/package_manager/src/Validator/DuplicateInfoFileValidator.php
index 56f9ec9478..fe1611d330 100644
--- a/package_manager/src/Validator/DuplicateInfoFileValidator.php
+++ b/package_manager/src/Validator/DuplicateInfoFileValidator.php
@@ -99,13 +99,7 @@ class DuplicateInfoFileValidator implements EventSubscriberInterface {
     $info_files = [];
     /** @var \Symfony\Component\Finder\SplFileInfo $info_file */
     foreach (iterator_to_array($info_files_finder) as $info_file) {
-      // Skipping info.yml files in tests/fixtures because Drupal will not scan
-      // these directories when doing extension discovery.
-      //
-      // @todo We should also skip info.yml files in tests/modules,
-      //   tests/themes, and tests/profiles directories in
-      //   https://www.drupal.org/i/3306163.
-      if (strpos($info_file->getPath(), DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'fixtures') !== FALSE) {
+      if ($this->skipInfoFile($info_file->getPath())) {
         continue;
       }
       $file_name = $info_file->getFilename();
@@ -114,4 +108,31 @@ class DuplicateInfoFileValidator implements EventSubscriberInterface {
     return $info_files;
   }
 
+  /**
+   * Determines if an info.yml file should be skipped.
+   *
+   * @param string $info_file_path
+   *   The path of the info.yml file.
+   *
+   * @return bool
+   *   TRUE if the info.yml file should be skipped, FALSE otherwise.
+   */
+  private function skipInfoFile(string $info_file_path): bool {
+    $directories_to_skip = [
+      DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'fixtures',
+      DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'modules',
+      DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'themes',
+      DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'profiles',
+    ];
+    foreach ($directories_to_skip as $directory_to_skip) {
+      // Skipping info.yml files in tests/fixtures, tests/modules, tests/themes,
+      // tests/profiles because Drupal will not scan these directories when
+      // doing extension discovery.
+      if (str_contains($info_file_path, $directory_to_skip)) {
+        return TRUE;
+      }
+    }
+    return FALSE;
+  }
+
 }
diff --git a/package_manager/tests/src/Kernel/DuplicateInfoFileValidatorTest.php b/package_manager/tests/src/Kernel/DuplicateInfoFileValidatorTest.php
index da3e3407ff..b8d9a743c5 100644
--- a/package_manager/tests/src/Kernel/DuplicateInfoFileValidatorTest.php
+++ b/package_manager/tests/src/Kernel/DuplicateInfoFileValidatorTest.php
@@ -47,7 +47,7 @@ class DuplicateInfoFileValidatorTest extends PackageManagerKernelTestBase {
         ],
         [],
       ],
-      'Duplicate info.yml files in stage with one file in tests folder' => [
+      'Duplicate info.yml files in stage with one file in tests/fixtures folder' => [
         [
           '/tests/fixtures/module.info.yml',
         ],
@@ -57,6 +57,36 @@ class DuplicateInfoFileValidatorTest extends PackageManagerKernelTestBase {
         ],
         [],
       ],
+      'Duplicate info.yml files in stage with one file in tests/modules folder' => [
+        [
+          '/tests/modules/module.info.yml',
+        ],
+        [
+          '/tests/modules/module.info.yml',
+          '/modules/module.info.yml',
+        ],
+        [],
+      ],
+      'Duplicate info.yml files in stage with one file in tests/themes folder' => [
+        [
+          '/tests/themes/theme.info.yml',
+        ],
+        [
+          '/tests/themes/theme.info.yml',
+          '/themes/theme.info.yml',
+        ],
+        [],
+      ],
+      'Duplicate info.yml files in stage with one file in tests/profiles folder' => [
+        [
+          '/tests/profiles/profile.info.yml',
+        ],
+        [
+          '/tests/profiles/profile.info.yml',
+          '/profiles/profile.info.yml',
+        ],
+        [],
+      ],
       'Duplicate info.yml files in stage not present in active' => [
         [],
         [
-- 
GitLab