9
9
10
10
use Magento \Framework \App \Filesystem \DirectoryList ;
11
11
use Magento \Framework \Filesystem ;
12
+ use Magento \Framework \Exception \FileSystemException ;
12
13
use Magento \Framework \Filesystem \Directory \WriteInterface ;
13
14
use Magento \TestFramework \Helper \Bootstrap ;
14
15
15
16
class FileTest extends \PHPUnit \Framework \TestCase
16
17
{
17
18
/**
18
- * @var \Magento\Framework\Filesystem\Driver\ File
19
+ * @var File
19
20
*/
20
- protected $ driver ;
21
+ private $ driver ;
21
22
22
23
/**
23
- * @var string
24
+ * @var String
24
25
*/
25
- protected $ absolutePath ;
26
+ private $ absolutePath ;
26
27
27
28
/**
28
- * get relative path for test
29
+ * @var String
30
+ */
31
+ private $ generatedPath ;
32
+
33
+ /**
34
+ * Returns relative path for the test.
29
35
*
30
36
* @param $relativePath
31
37
* @return string
@@ -36,16 +42,26 @@ protected function getTestPath($relativePath)
36
42
}
37
43
38
44
/**
39
- * Set up
45
+ * @inheritdoc
40
46
*/
41
47
public function setUp ()
42
48
{
43
- $ this ->driver = new \ Magento \ Framework \ Filesystem \ Driver \ File ();
49
+ $ this ->driver = new File ();
44
50
$ 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 ();
45
61
}
46
62
47
63
/**
48
- * test read recursively read
64
+ * Tests directory recursive read.
49
65
*/
50
66
public function testReadDirectoryRecursively ()
51
67
{
@@ -63,7 +79,7 @@ public function testReadDirectoryRecursively()
63
79
}
64
80
65
81
/**
66
- * test exception
82
+ * Tests directory reading exception.
67
83
*
68
84
* @expectedException \Magento\Framework\Exception\FileSystemException
69
85
*/
@@ -72,6 +88,11 @@ public function testReadDirectoryRecursivelyFailure()
72
88
$ this ->driver ->readDirectoryRecursively ($ this ->getTestPath ('not-existing-directory ' ));
73
89
}
74
90
91
+ /**
92
+ * Tests of directory creating.
93
+ *
94
+ * @throws FileSystemException
95
+ */
75
96
public function testCreateDirectory ()
76
97
{
77
98
$ generatedPath = $ this ->getTestPath ('generated/roo/bar/baz/foo ' );
@@ -123,4 +144,39 @@ public function createFileDataProvider()
123
144
]
124
145
];
125
146
}
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
+ }
126
182
}
0 commit comments