Skip to content
Snippets Groups Projects
Commit 4e5e5b13 authored by omkar podey's avatar omkar podey Committed by Ted Bowman
Browse files

Issue #3335802 by omkar.podey, tedbow: Add addDotGitFolder functionality to...

Issue #3335802 by omkar.podey, tedbow: Add addDotGitFolder functionality to \Drupal\fixture_manipulator\FixtureManipulator
parent f006b3fd
No related branches found
No related tags found
1 merge request!668Issue #3335802: Add addDotGitFolder functionality to \Drupal\fixture_manipulator\FixtureManipulator
......@@ -351,4 +351,23 @@ class FixtureManipulator {
}
}
/**
* Creates an empty .git folder after being provided a path.
*/
public function addDotGitFolder(string $path): self {
if (!$this->committingChanges) {
$this->manipulatorArguments['addDotGitFolder'][] = func_get_args();
return $this;
}
$fs = new Filesystem();
$git_directory_path = $path . "/.git";
if (!is_dir($git_directory_path)) {
$fs->mkdir($git_directory_path);
}
else {
throw new \LogicException("A .git directory already exists at $path.");
}
return $this;
}
}
......@@ -390,6 +390,35 @@ class FixtureManipulatorTest extends PackageManagerKernelTestBase {
);
}
/**
* @covers ::addDotGitFolder
*/
public function testAddDotGitFolder() {
$project_root = $this->container->get('package_manager.path_locator')->getProjectRoot();
$this->assertFalse(is_dir($project_root . "/relative/path/.git"));
$fixture_manipulator = (new FixtureManipulator())
->addPackage([
'name' => 'relative/project_path',
'install_path' => '../../relative/project_path',
'type' => 'drupal-module',
])
->addDotGitFolder($project_root . "/relative/project_path")
->addDotGitFolder($project_root . "/relative/path");
$this->assertTrue(!is_dir($project_root . "/relative/project_path/.git"));
$fixture_manipulator->commitChanges($project_root);
$this->assertTrue(is_dir($project_root . "/relative/path/.git"));
// We should not be able to create already existing directory.
try {
(new FixtureManipulator())
->addDotGitFolder($project_root . "/relative/path")
->commitChanges($project_root);
$this->fail('Trying to create a .git directory that already exists should raise an error.');
}
catch (\LogicException $e) {
$this->assertStringContainsString("A .git directory already exists at " . $project_root, $e->getMessage());
}
}
public function stageManipulatorUsageStyles() {
return [
'immediately destroyed' => [TRUE],
......
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