diff --git a/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php b/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php index a29e2da91638b925f9912faafa23b93f7919527f..50791685f55b206178a8f0ee1030eb62518ebaa0 100644 --- a/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php +++ b/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php @@ -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; + } + } diff --git a/package_manager/tests/src/Kernel/FixtureManipulatorTest.php b/package_manager/tests/src/Kernel/FixtureManipulatorTest.php index cb1f734093cd4d032b2342f48c40d01e2005b565..4153fc44687f72b6f6390090f0e3ed714c9a38f6 100644 --- a/package_manager/tests/src/Kernel/FixtureManipulatorTest.php +++ b/package_manager/tests/src/Kernel/FixtureManipulatorTest.php @@ -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],