function FixtureManipulatorTest::testAddDotGitFolder
@covers ::addDotGitFolder
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ FixtureManipulatorTest.php, line 218
Class
- FixtureManipulatorTest
- @coversDefaultClass \Drupal\fixture_manipulator\FixtureManipulator
Namespace
Drupal\Tests\package_manager\KernelCode
public function testAddDotGitFolder() : void {
$path_locator = $this->container
->get(PathLocator::class);
$project_root = $path_locator->getProjectRoot();
$this->assertFalse(is_dir($project_root . "/relative/path/.git"));
// We should not be able to add a git folder to a non-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->assertSame('No directory exists at ' . $project_root . '/relative/path.', $e->getMessage());
}
mkdir($project_root . "/relative/path", 0777, TRUE);
$fixture_manipulator = (new FixtureManipulator())->addPackage([
'name' => 'relative/project_path',
'type' => 'drupal-module',
])
->addDotGitFolder($path_locator->getVendorDirectory() . "/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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.