Skip to content

Commit d732070

Browse files
committed
[Filesystem] symlink() creates target directories
1 parent 519b595 commit d732070

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Filesystem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
152152
return;
153153
}
154154

155+
$this->mkdir(dirname($targetDir));
156+
155157
$ok = false;
156158
if (is_link($targetDir)) {
157159
if (readlink($targetDir) != $originDir) {

Tests/FilesystemTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,23 @@ public function testSymlinkIsNotOverwrittenIfAlreadyCreated()
454454
$this->assertEquals($file, readlink($link));
455455
}
456456

457+
public function testSymlinkCreatesTargetDirectoryIfItDoesNotExist()
458+
{
459+
$this->markAsSkippedIfSymlinkIsMissing();
460+
461+
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
462+
$link1 = $this->workspace.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'link';
463+
$link2 = $this->workspace.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'subdir'.DIRECTORY_SEPARATOR.'link';
464+
465+
$this->filesystem->symlink($file, $link1);
466+
$this->filesystem->symlink($file, $link2);
467+
468+
$this->assertTrue(is_link($link1));
469+
$this->assertEquals($file, readlink($link1));
470+
$this->assertTrue(is_link($link2));
471+
$this->assertEquals($file, readlink($link2));
472+
}
473+
457474
/**
458475
* @dataProvider providePathsForMakePathRelative
459476
*/

0 commit comments

Comments
 (0)