diff --git a/package_manager/tests/src/Kernel/FixtureUtility.php b/package_manager/tests/src/Kernel/FixtureUtility.php deleted file mode 100644 index 3b6a0b667dbba2b9f8dcbf255fd315bb877ccdd0..0000000000000000000000000000000000000000 --- a/package_manager/tests/src/Kernel/FixtureUtility.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -namespace Drupal\Tests\package_manager\Kernel; - -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator; - -/** - * A utility for all things fixtures. - */ -class FixtureUtility { - - /** - * If a fixture path has been set, mirrors it to the given path. - * - * @param string $source_path - * The source path. - * @param string $destination_path - * The path to which the fixture files should be mirrored. - */ - public static function copyFixtureFilesTo(string $source_path, string $destination_path): void { - (new Filesystem())->mirror($source_path, $destination_path, NULL, [ - 'override' => TRUE, - 'delete' => TRUE, - ]); - static::cleanUpFixtureFiles($destination_path); - } - - /** - * Clean up fixture files. - * - * @param string $destination_path - * The destination path. - */ - private static function cleanUpFixtureFiles(string $destination_path) { - static::renameInfoYmlFiles($destination_path); - static::renameGitDirectories($destination_path); - } - - /** - * Renames all files that end with .info.yml.hide. - * - * @param string $dir - * The directory to be iterated through. - */ - protected static 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())); - } - } - } - - /** - * Renames _git directories to .git. - * - * @param string $dir - * The directory to be iterated through. - */ - private static function renameGitDirectories(string $dir) { - // Construct the iterator. - $it = new \DirectoryIterator($dir); - - // Loop through files and rename them. - /** @var \Symfony\Component\Finder\SplFileInfo $file */ - foreach ($it as $file) { - if ($file->isDir() && $file->getFilename() === '_git') { - rename( - $file->getPathname(), - $file->getPath() . DIRECTORY_SEPARATOR . '.git' - ); - } - } - } - -} diff --git a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php index 52fb14ad102810248c075fd3b5fda57d26a2f021..280bb133275359e1bbeedd8fc5844c5802e79830 100644 --- a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php +++ b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php @@ -19,6 +19,9 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Utils; use org\bovigo\vfs\vfsStream; +use org\bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamFile; +use org\bovigo\vfs\visitor\vfsStreamAbstractVisitor; use PhpTuf\ComposerStager\Domain\Value\Path\PathInterface; use PhpTuf\ComposerStager\Infrastructure\Factory\Path\PathFactoryInterface; use PhpTuf\ComposerStager\Infrastructure\Value\Path\AbstractPath; @@ -215,7 +218,31 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { // Create the active directory and copy its contents from a fixture. $active_dir = vfsStream::newDirectory('active'); $this->vfsRoot->addChild($active_dir); - FixtureUtility::copyFixtureFilesTo($source_dir, $active_dir->url()); + vfsStream::copyFromFileSystem($source_dir, $active_dir); + + // Because we can't commit physical `.git` directories into the fixture, use + // a visitor to traverse the virtual file system and rename all `_git` + // directories to `.git`. + vfsStream::inspect(new class () extends vfsStreamAbstractVisitor { + + /** + * {@inheritdoc} + */ + public function visitFile(vfsStreamFile $file) {} + + /** + * {@inheritdoc} + */ + public function visitDirectory(vfsStreamDirectory $dir) { + if ($dir->getName() === '_git') { + $dir->rename('.git'); + } + foreach ($dir->getChildren() as $child) { + $this->visit($child); + } + } + + }); // Create a staging root directory alongside the active directory. $stage_dir = vfsStream::newDirectory('stage');