From 4e5e5b1391673f154089ef0eba1a31494127e3c1 Mon Sep 17 00:00:00 2001 From: omkar podey <58183-omkar.podey@users.noreply.drupalcode.org> Date: Tue, 24 Jan 2023 16:41:47 +0000 Subject: [PATCH] Issue #3335802 by omkar.podey, tedbow: Add addDotGitFolder functionality to \Drupal\fixture_manipulator\FixtureManipulator --- .../src/FixtureManipulator.php | 19 ++++++++++++ .../src/Kernel/FixtureManipulatorTest.php | 29 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php b/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php index a29e2da916..50791685f5 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 cb1f734093..4153fc4468 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], -- GitLab