Skip to content
Snippets Groups Projects
Commit d64c9f30 authored by Ted Bowman's avatar Ted Bowman
Browse files

Revert "start FixtureUtility.php"

This reverts commit da6f5255.
parent e9f8a1c4
No related branches found
No related tags found
No related merge requests found
<?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'
);
}
}
}
}
......@@ -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');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment