1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MapperTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
use kalanis\kw_mapper\MapperException; |
8
|
|
|
use kalanis\kw_paths\PathsException; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class DirFailTest extends AStorageTest |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @throws FilesException |
15
|
|
|
* @throws MapperException |
16
|
|
|
* @throws PathsException |
17
|
|
|
*/ |
18
|
|
|
public function testCreate(): void |
19
|
|
|
{ |
20
|
|
|
if ($this->skipIt) { |
21
|
|
|
$this->markTestSkipped('Skipped by config'); |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$this->dataRefill(); |
26
|
|
|
|
27
|
|
|
$lib = $this->getDirFailLib(); |
28
|
|
|
$this->expectException(FilesException::class); |
29
|
|
|
$lib->createDir(['another'], false); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @throws FilesException |
34
|
|
|
* @throws MapperException |
35
|
|
|
* @throws PathsException |
36
|
|
|
*/ |
37
|
|
|
public function testRead(): void |
38
|
|
|
{ |
39
|
|
|
if ($this->skipIt) { |
40
|
|
|
$this->markTestSkipped('Skipped by config'); |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->dataRefill(); |
45
|
|
|
|
46
|
|
|
$lib = $this->getDirFailLib(); |
47
|
|
|
$this->expectException(FilesException::class); |
48
|
|
|
$lib->readDir([''], false, true); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @throws FilesException |
53
|
|
|
* @throws MapperException |
54
|
|
|
* @throws PathsException |
55
|
|
|
*/ |
56
|
|
|
public function testCopy(): void |
57
|
|
|
{ |
58
|
|
|
if ($this->skipIt) { |
59
|
|
|
$this->markTestSkipped('Skipped by config'); |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->dataRefill(); |
64
|
|
|
|
65
|
|
|
$lib = $this->getDirFailLib(); |
66
|
|
|
$this->expectException(FilesException::class); |
67
|
|
|
$lib->copyDir(['next_one'], ['more']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @throws FilesException |
72
|
|
|
* @throws MapperException |
73
|
|
|
* @throws PathsException |
74
|
|
|
*/ |
75
|
|
|
public function testCopyUnknown(): void |
76
|
|
|
{ |
77
|
|
|
if ($this->skipIt) { |
78
|
|
|
$this->markTestSkipped('Skipped by config'); |
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->dataRefill(); |
83
|
|
|
|
84
|
|
|
$lib = $this->getDirLib(); |
85
|
|
|
$this->assertFalse($lib->copyDir(['not source'], ['extra2'])); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @throws FilesException |
90
|
|
|
* @throws MapperException |
91
|
|
|
* @throws PathsException |
92
|
|
|
*/ |
93
|
|
|
public function testCopyToUnknownDir(): void |
94
|
|
|
{ |
95
|
|
|
if ($this->skipIt) { |
96
|
|
|
$this->markTestSkipped('Skipped by config'); |
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->dataRefill(); |
101
|
|
|
|
102
|
|
|
$lib = $this->getDirLib(); |
103
|
|
|
$this->assertFalse($lib->copyDir(['next_one', 'sub_one'], ['unknown', 'last_one'])); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @throws FilesException |
108
|
|
|
* @throws MapperException |
109
|
|
|
* @throws PathsException |
110
|
|
|
*/ |
111
|
|
|
public function testCopyToExisting(): void |
112
|
|
|
{ |
113
|
|
|
if ($this->skipIt) { |
114
|
|
|
$this->markTestSkipped('Skipped by config'); |
115
|
|
|
return; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->dataRefill(); |
119
|
|
|
|
120
|
|
|
$lib = $this->getDirLib(); |
121
|
|
|
$this->assertFalse($lib->copyDir(['next_one', 'sub_one'], ['last_one'])); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @throws FilesException |
126
|
|
|
* @throws MapperException |
127
|
|
|
* @throws PathsException |
128
|
|
|
*/ |
129
|
|
|
public function testCopyToSub(): void |
130
|
|
|
{ |
131
|
|
|
if ($this->skipIt) { |
132
|
|
|
$this->markTestSkipped('Skipped by config'); |
133
|
|
|
return; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$this->dataRefill(); |
137
|
|
|
|
138
|
|
|
$lib = $this->getDirLib(); |
139
|
|
|
$this->assertFalse($lib->copyDir(['next_one', 'sub_one'], ['next_one', 'sub_one', 'deeper'])); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @throws FilesException |
144
|
|
|
* @throws MapperException |
145
|
|
|
* @throws PathsException |
146
|
|
|
*/ |
147
|
|
|
public function testMove(): void |
148
|
|
|
{ |
149
|
|
|
if ($this->skipIt) { |
150
|
|
|
$this->markTestSkipped('Skipped by config'); |
151
|
|
|
return; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$this->dataRefill(); |
155
|
|
|
|
156
|
|
|
$lib = $this->getDirFailLib(); |
157
|
|
|
$this->expectException(FilesException::class); |
158
|
|
|
$lib->moveDir(['more'], ['another']); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @throws FilesException |
163
|
|
|
* @throws MapperException |
164
|
|
|
* @throws PathsException |
165
|
|
|
*/ |
166
|
|
|
public function testMoveUnknown(): void |
167
|
|
|
{ |
168
|
|
|
if ($this->skipIt) { |
169
|
|
|
$this->markTestSkipped('Skipped by config'); |
170
|
|
|
return; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->dataRefill(); |
174
|
|
|
|
175
|
|
|
$lib = $this->getDirLib(); |
176
|
|
|
$this->assertFalse($lib->moveDir(['not source'], ['extra2'])); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @throws FilesException |
181
|
|
|
* @throws MapperException |
182
|
|
|
* @throws PathsException |
183
|
|
|
*/ |
184
|
|
|
public function testMoveToUnknownDir(): void |
185
|
|
|
{ |
186
|
|
|
if ($this->skipIt) { |
187
|
|
|
$this->markTestSkipped('Skipped by config'); |
188
|
|
|
return; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$this->dataRefill(); |
192
|
|
|
|
193
|
|
|
$lib = $this->getDirLib(); |
194
|
|
|
$this->assertFalse($lib->moveDir(['next_one', 'sub_one'], ['unknown', 'last_one'])); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @throws FilesException |
199
|
|
|
* @throws MapperException |
200
|
|
|
* @throws PathsException |
201
|
|
|
*/ |
202
|
|
|
public function testMoveToExisting(): void |
203
|
|
|
{ |
204
|
|
|
if ($this->skipIt) { |
205
|
|
|
$this->markTestSkipped('Skipped by config'); |
206
|
|
|
return; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
$this->dataRefill(); |
210
|
|
|
|
211
|
|
|
$lib = $this->getDirLib(); |
212
|
|
|
$this->assertFalse($lib->moveDir(['next_one', 'sub_one'], ['last_one'])); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @throws FilesException |
217
|
|
|
* @throws MapperException |
218
|
|
|
* @throws PathsException |
219
|
|
|
*/ |
220
|
|
|
public function testMoveToSub(): void |
221
|
|
|
{ |
222
|
|
|
if ($this->skipIt) { |
223
|
|
|
$this->markTestSkipped('Skipped by config'); |
224
|
|
|
return; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
$this->dataRefill(); |
228
|
|
|
|
229
|
|
|
$lib = $this->getDirLib(); |
230
|
|
|
$this->assertFalse($lib->moveDir(['next_one', 'sub_one'], ['next_one', 'sub_one', 'deeper'])); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @throws FilesException |
235
|
|
|
* @throws MapperException |
236
|
|
|
* @throws PathsException |
237
|
|
|
*/ |
238
|
|
|
public function testDelete(): void |
239
|
|
|
{ |
240
|
|
|
if ($this->skipIt) { |
241
|
|
|
$this->markTestSkipped('Skipped by config'); |
242
|
|
|
return; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$this->dataRefill(); |
246
|
|
|
|
247
|
|
|
$lib = $this->getDirFailLib(); |
248
|
|
|
$this->expectException(FilesException::class); |
249
|
|
|
$lib->deleteDir(['another'], true); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @throws FilesException |
254
|
|
|
* @throws MapperException |
255
|
|
|
* @throws PathsException |
256
|
|
|
*/ |
257
|
|
|
public function testDeleteFile(): void |
258
|
|
|
{ |
259
|
|
|
if ($this->skipIt) { |
260
|
|
|
$this->markTestSkipped('Skipped by config'); |
261
|
|
|
return; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
$this->dataRefill(); |
265
|
|
|
|
266
|
|
|
$lib = $this->getDirLib(); |
267
|
|
|
$this->assertFalse($lib->deleteDir(['sub', 'dummy3.txt'])); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @throws FilesException |
272
|
|
|
* @throws MapperException |
273
|
|
|
* @throws PathsException |
274
|
|
|
*/ |
275
|
|
|
public function testDeleteNonEmpty(): void |
276
|
|
|
{ |
277
|
|
|
if ($this->skipIt) { |
278
|
|
|
$this->markTestSkipped('Skipped by config'); |
279
|
|
|
return; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
$this->dataRefill(); |
283
|
|
|
|
284
|
|
|
$lib = $this->getDirLib(); |
285
|
|
|
$this->assertFalse($lib->deleteDir(['next_one'])); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @throws FilesException |
290
|
|
|
* @throws PathsException |
291
|
|
|
*/ |
292
|
|
|
public function testDeepDeleteFail(): void |
293
|
|
|
{ |
294
|
|
|
$lib = $this->getDirLib(); |
295
|
|
|
$this->assertTrue($lib->createDir(['some', 'more'], true)); |
296
|
|
|
$this->assertFalse($lib->deleteDir(['some'])); |
297
|
|
|
$this->assertTrue($lib->deleteDir(['some'], true)); |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|