From a8dfeaaefaf055ddf3f6df3b1e28ee0523a466b0 Mon Sep 17 00:00:00 2001
From: Ted Bowman <ted+git@tedbow.com>
Date: Fri, 9 Sep 2022 11:36:21 -0400
Subject: [PATCH] remove need for different renameInfoYmlFiles versions

---
 ...tomaticUpdatesExtensionsKernelTestBase.php |  4 --
 .../tests/src/Kernel/ExtensionUpdaterTest.php |  3 --
 .../tests/src/Kernel/ComposerUtilityTest.php  |  6 +--
 .../src/Traits/InfoYmlConverterTrait.php      | 48 -------------------
 tests/src/Build/UpdateTestBase.php            | 26 +---------
 .../AutomaticUpdatesFunctionalTestBase.php    | 29 +----------
 6 files changed, 5 insertions(+), 111 deletions(-)
 delete mode 100644 package_manager/tests/src/Traits/InfoYmlConverterTrait.php

diff --git a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php
index a6357c9c77..04bc6d7342 100644
--- a/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php
+++ b/automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php
@@ -8,15 +8,12 @@ use Drupal\package_manager\Exception\StageValidationException;
 use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase;
 use Drupal\Tests\package_manager\Kernel\TestPathFactory;
 use Drupal\Tests\package_manager\Kernel\TestStageTrait;
-use Drupal\Tests\package_manager\Traits\InfoYmlConverterTrait;
 
 /**
  * Base class for kernel tests of the Automatic Updates Extensions module.
  */
 abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdatesKernelTestBase {
 
-  use InfoYmlConverterTrait;
-
   /**
    * {@inheritdoc}
    */
@@ -47,7 +44,6 @@ abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdates
   protected function createVirtualProject(?string $source_dir = NULL): void {
     $source_dir = $source_dir ?? __DIR__ . '/../../fixtures/fake-site';
     parent::createVirtualProject($source_dir);
-    $this->renameVfsInfoYmlFiles();
   }
 
   /**
diff --git a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php
index b052627084..3f9040ce4d 100644
--- a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php
+++ b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests\automatic_updates_extensions\Kernel;
 
 use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase;
-use Drupal\Tests\package_manager\Traits\InfoYmlConverterTrait;
 use Drupal\Tests\user\Traits\UserCreationTrait;
 
 /**
@@ -14,7 +13,6 @@ use Drupal\Tests\user\Traits\UserCreationTrait;
 class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase {
 
   use UserCreationTrait;
-  use InfoYmlConverterTrait;
 
   /**
    * {@inheritdoc}
@@ -42,7 +40,6 @@ class ExtensionUpdaterTest extends AutomaticUpdatesKernelTestBase {
     $this->setCurrentUser($user);
 
     $this->createVirtualProject(__DIR__ . '/../../fixtures/fake-site');
-    $this->renameVfsInfoYmlFiles();
   }
 
   /**
diff --git a/package_manager/tests/src/Kernel/ComposerUtilityTest.php b/package_manager/tests/src/Kernel/ComposerUtilityTest.php
index 29023f1d45..1532642163 100644
--- a/package_manager/tests/src/Kernel/ComposerUtilityTest.php
+++ b/package_manager/tests/src/Kernel/ComposerUtilityTest.php
@@ -4,7 +4,6 @@ namespace Drupal\Tests\package_manager\Kernel;
 
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\package_manager\ComposerUtility;
-use Drupal\Tests\package_manager\Traits\InfoYmlConverterTrait;
 use org\bovigo\vfs\vfsStream;
 
 /**
@@ -14,8 +13,6 @@ use org\bovigo\vfs\vfsStream;
  */
 class ComposerUtilityTest extends KernelTestBase {
 
-  use InfoYmlConverterTrait;
-
   /**
    * {@inheritdoc}
    */
@@ -28,9 +25,8 @@ class ComposerUtilityTest extends KernelTestBase {
     parent::setUp();
 
     $fixture = vfsStream::newDirectory('fixture');
-    vfsStream::copyFromFileSystem(__DIR__ . '/../../fixtures/project_package_conversion', $fixture);
     $this->vfsRoot->addChild($fixture);
-    $this->renameVfsInfoYmlFiles();
+    FixtureUtility::copyFixtureFilesTo(__DIR__ . '/../../fixtures/project_package_conversion', $fixture->url());
   }
 
   /**
diff --git a/package_manager/tests/src/Traits/InfoYmlConverterTrait.php b/package_manager/tests/src/Traits/InfoYmlConverterTrait.php
deleted file mode 100644
index 4f186a53fa..0000000000
--- a/package_manager/tests/src/Traits/InfoYmlConverterTrait.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-namespace Drupal\Tests\package_manager\Traits;
-
-use org\bovigo\vfs\vfsStream;
-use org\bovigo\vfs\vfsStreamDirectory;
-use org\bovigo\vfs\vfsStreamFile;
-use org\bovigo\vfs\visitor\vfsStreamAbstractVisitor;
-
-/**
- * Common methods to convert info.yml file that will pass core coding standards.
- */
-trait InfoYmlConverterTrait {
-
-  /**
-   * Renames all files that end with .info.yml.hide.
-   */
-  protected function renameVfsInfoYmlFiles(): void {
-    // Strip the `.hide` suffix from all `.info.yml.hide` files. Drupal's coding
-    // standards don't allow info files to have the `project` key, but we need
-    // it to be present for testing.
-    vfsStream::inspect(new class () extends vfsStreamAbstractVisitor {
-
-      /**
-       * {@inheritdoc}
-       */
-      public function visitFile(vfsStreamFile $file) {
-        $name = $file->getName();
-
-        if (str_ends_with($name, '.info.yml.hide')) {
-          $new_name = basename($name, '.hide');
-          $file->rename($new_name);
-        }
-      }
-
-      /**
-       * {@inheritdoc}
-       */
-      public function visitDirectory(vfsStreamDirectory $dir) {
-        foreach ($dir->getChildren() as $child) {
-          $this->visit($child);
-        }
-      }
-
-    });
-  }
-
-}
diff --git a/tests/src/Build/UpdateTestBase.php b/tests/src/Build/UpdateTestBase.php
index 32d754d758..35ef9ad3ae 100644
--- a/tests/src/Build/UpdateTestBase.php
+++ b/tests/src/Build/UpdateTestBase.php
@@ -5,8 +5,7 @@ namespace Drupal\Tests\automatic_updates\Build;
 use Drupal\Component\Utility\Html;
 use Drupal\Tests\package_manager\Build\TemplateProjectTestBase;
 use Drupal\Tests\RandomGeneratorTrait;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
+use Drupal\Tests\package_manager\Kernel\FixtureUtility;
 
 /**
  * Base class for tests that perform in-place updates.
@@ -117,29 +116,8 @@ END;
    */
   protected function copyFixtureToTempDirectory(string $fixture_directory): string {
     $temp_directory = $this->getWorkspaceDirectory() . '/fixtures_temp_' . $this->randomMachineName(20);
-    (new Filesystem())->mirror($fixture_directory, $temp_directory);
-    $this->assertDirectoryIsWritable($temp_directory);
-    $this->renameInfoYmlFiles($temp_directory);
+    FixtureUtility::copyFixtureFilesTo($fixture_directory, $temp_directory);
     return $temp_directory;
   }
 
-  /**
-   * Renames all files that end with .info.yml.hide.
-   *
-   * @param string $dir
-   *   The directory to be iterated through.
-   */
-  protected function renameInfoYmlFiles(string $dir) {
-    // Construct the iterator.
-    $it = new RecursiveDirectoryIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
-
-    // Loop through files and rename them.
-    foreach (new \RecursiveIteratorIterator($it) as $file) {
-      if ($file->getExtension() == 'hide') {
-        rename($file->getPathname(), $dir . DIRECTORY_SEPARATOR .
-            $file->getRelativePath() . DIRECTORY_SEPARATOR . str_replace(".hide", "", $file->getFilename()));
-      }
-    }
-  }
-
 }
diff --git a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php
index 7b2cc2216c..33e15cba15 100644
--- a/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php
+++ b/tests/src/Functional/AutomaticUpdatesFunctionalTestBase.php
@@ -6,9 +6,8 @@ use Drupal\Core\Site\Settings;
 use Drupal\package_manager_bypass\Beginner;
 use Drupal\package_manager_bypass\Stager;
 use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\package_manager\Kernel\FixtureUtility;
 use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
 
 /**
  * Base class for functional tests of the Automatic Updates module.
@@ -174,8 +173,7 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
    */
   protected function copyFixtureToTempDirectory(string $fixture_directory): string {
     $temp_directory = $this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . DIRECTORY_SEPARATOR . $this->randomMachineName(20);
-    (new Filesystem())->mirror($fixture_directory, $temp_directory);
-    $this->assertDirectoryIsWritable($temp_directory);
+    FixtureUtility::copyFixtureFilesTo($fixture_directory, $temp_directory);
     return $temp_directory;
   }
 
@@ -193,8 +191,6 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
     Beginner::setFixturePath($active_dir);
     $this->container->get('package_manager.path_locator')
       ->setPaths($active_dir, $active_dir . '/vendor', '', NULL);
-
-    $this->renameInfoYmlFiles($active_dir);
   }
 
   /**
@@ -209,27 +205,6 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
     // directory and not affect other tests.
     $staged_dir = $this->copyFixtureToTempDirectory($fixture_directory);
     Stager::setFixturePath($staged_dir);
-
-    $this->renameInfoYmlFiles($staged_dir);
-  }
-
-  /**
-   * Renames all files that end with .info.yml.hide.
-   *
-   * @param string $dir
-   *   The directory to be iterated through.
-   */
-  protected function renameInfoYmlFiles(string $dir) {
-    // Construct the iterator.
-    $it = new RecursiveDirectoryIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
-
-    // Loop through files and rename them.
-    foreach (new \RecursiveIteratorIterator($it) as $file) {
-      if ($file->getExtension() == 'hide') {
-        rename($file->getPathname(), $dir . DIRECTORY_SEPARATOR . $file->getRelativePath() . DIRECTORY_SEPARATOR . str_replace(".hide", "", $file->getFilename()));
-      }
-    }
-
   }
 
 }
-- 
GitLab