Skip to content

Commit d77a325

Browse files
Merge remote-tracking branch 'origin/MAGETWO-94154' into 2.2-develop-pr4
2 parents fd89b79 + 0e9d2e6 commit d77a325

File tree

2 files changed

+78
-11
lines changed
  • dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver
  • lib/internal/Magento/Framework/Filesystem/Driver

2 files changed

+78
-11
lines changed

dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,29 @@
99

1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\Filesystem;
12+
use Magento\Framework\Exception\FileSystemException;
1213
use Magento\Framework\Filesystem\Directory\WriteInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
1415

1516
class FileTest extends \PHPUnit\Framework\TestCase
1617
{
1718
/**
18-
* @var \Magento\Framework\Filesystem\Driver\File
19+
* @var File
1920
*/
20-
protected $driver;
21+
private $driver;
2122

2223
/**
23-
* @var string
24+
* @var String
2425
*/
25-
protected $absolutePath;
26+
private $absolutePath;
2627

2728
/**
28-
* get relative path for test
29+
* @var String
30+
*/
31+
private $generatedPath;
32+
33+
/**
34+
* Returns relative path for the test.
2935
*
3036
* @param $relativePath
3137
* @return string
@@ -36,16 +42,26 @@ protected function getTestPath($relativePath)
3642
}
3743

3844
/**
39-
* Set up
45+
* @inheritdoc
4046
*/
4147
public function setUp()
4248
{
43-
$this->driver = new \Magento\Framework\Filesystem\Driver\File();
49+
$this->driver = new File();
4450
$this->absolutePath = dirname(__DIR__) . '/_files/';
51+
$this->generatedPath = $this->getTestPath('generated');
52+
$this->removeGeneratedDirectory();
53+
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
protected function tearDown()
59+
{
60+
$this->removeGeneratedDirectory();
4561
}
4662

4763
/**
48-
* test read recursively read
64+
* Tests directory recursive read.
4965
*/
5066
public function testReadDirectoryRecursively()
5167
{
@@ -63,7 +79,7 @@ public function testReadDirectoryRecursively()
6379
}
6480

6581
/**
66-
* test exception
82+
* Tests directory reading exception.
6783
*
6884
* @expectedException \Magento\Framework\Exception\FileSystemException
6985
*/
@@ -72,6 +88,11 @@ public function testReadDirectoryRecursivelyFailure()
7288
$this->driver->readDirectoryRecursively($this->getTestPath('not-existing-directory'));
7389
}
7490

91+
/**
92+
* Tests of directory creating.
93+
*
94+
* @throws FileSystemException
95+
*/
7596
public function testCreateDirectory()
7697
{
7798
$generatedPath = $this->getTestPath('generated/roo/bar/baz/foo');
@@ -123,4 +144,39 @@ public function createFileDataProvider()
123144
]
124145
];
125146
}
147+
148+
/**
149+
* Tests creation and removing of symlinks.
150+
*
151+
* @throws FileSystemException
152+
* @return void
153+
*/
154+
public function testSymlinks()
155+
{
156+
$sourceDirectory = $this->generatedPath . '/source';
157+
$destinationDirectory = $this->generatedPath . '/destination';
158+
159+
$this->driver->createDirectory($sourceDirectory);
160+
$this->driver->createDirectory($destinationDirectory);
161+
162+
$linkName = $destinationDirectory . '/link';
163+
164+
self::assertTrue($this->driver->isWritable($destinationDirectory));
165+
self::assertTrue($this->driver->symlink($sourceDirectory, $linkName));
166+
self::assertTrue($this->driver->isExists($linkName));
167+
self::assertTrue($this->driver->deleteDirectory($linkName));
168+
}
169+
170+
/**
171+
* Remove generated directories.
172+
*
173+
* @throws FileSystemException
174+
* @return void
175+
*/
176+
private function removeGeneratedDirectory()
177+
{
178+
if (is_dir($this->generatedPath)) {
179+
$this->driver->deleteDirectory($this->generatedPath);
180+
}
181+
}
126182
}

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
/**
1515
* Class File
16+
*
1617
* @package Magento\Framework\Filesystem\Driver
1718
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1819
*/
@@ -405,7 +406,14 @@ public function deleteDirectory($path)
405406
$this->deleteFile($entity->getPathname());
406407
}
407408
}
408-
$result = @rmdir($this->getScheme() . $path);
409+
410+
$fullPath = $this->getScheme() . $path;
411+
if (is_link($fullPath)) {
412+
$result = @unlink($fullPath);
413+
} else {
414+
$result = @rmdir($fullPath);
415+
}
416+
409417
if (!$result) {
410418
throw new FileSystemException(
411419
new \Magento\Framework\Phrase(
@@ -836,6 +844,8 @@ public function fileUnlock($resource)
836844
}
837845

838846
/**
847+
* Returns an absolute path for the given one.
848+
*
839849
* @param string $basePath
840850
* @param string $path
841851
* @param string|null $scheme
@@ -872,7 +882,8 @@ public function getRelativePath($basePath, $path = null)
872882
}
873883

874884
/**
875-
* Fixes path separator
885+
* Fixes path separator.
886+
*
876887
* Utility method.
877888
*
878889
* @param string $path

0 commit comments

Comments
 (0)