1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace StorageBasicTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
use kalanis\kw_paths\PathsException; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class DirFailTest extends AStorageTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @throws FilesException |
14
|
|
|
* @throws PathsException |
15
|
|
|
*/ |
16
|
|
|
public function testCreate(): void |
17
|
|
|
{ |
18
|
|
|
$lib = $this->getDirFailLib(); |
19
|
|
|
$this->expectException(FilesException::class); |
20
|
|
|
$lib->createDir(['another'], false); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @throws FilesException |
25
|
|
|
* @throws PathsException |
26
|
|
|
*/ |
27
|
|
|
public function testRead(): void |
28
|
|
|
{ |
29
|
|
|
$lib = $this->getDirFailLib(); |
30
|
|
|
$this->expectException(FilesException::class); |
31
|
|
|
$lib->readDir([''], false, true); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws FilesException |
36
|
|
|
* @throws PathsException |
37
|
|
|
*/ |
38
|
|
|
public function testCopy(): void |
39
|
|
|
{ |
40
|
|
|
$lib = $this->getDirFailLib(); |
41
|
|
|
$this->expectException(FilesException::class); |
42
|
|
|
$lib->copyDir(['next_one'], ['more']); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @throws FilesException |
47
|
|
|
* @throws PathsException |
48
|
|
|
*/ |
49
|
|
|
public function testCopyUnknown(): void |
50
|
|
|
{ |
51
|
|
|
$lib = $this->getDirLib(); |
52
|
|
|
$this->assertFalse($lib->copyDir(['not source'], ['extra2'])); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws FilesException |
57
|
|
|
* @throws PathsException |
58
|
|
|
*/ |
59
|
|
|
public function testCopyToUnknownDir(): void |
60
|
|
|
{ |
61
|
|
|
$lib = $this->getDirLib(); |
62
|
|
|
$this->assertFalse($lib->copyDir(['next_one', 'sub_one'], ['unknown', 'last_one'])); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @throws FilesException |
67
|
|
|
* @throws PathsException |
68
|
|
|
*/ |
69
|
|
|
public function testCopyToExisting(): void |
70
|
|
|
{ |
71
|
|
|
$lib = $this->getDirLib(); |
72
|
|
|
$this->assertFalse($lib->copyDir(['next_one', 'sub_one'], ['last_one'])); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @throws FilesException |
77
|
|
|
* @throws PathsException |
78
|
|
|
*/ |
79
|
|
|
public function testCopyToSub(): void |
80
|
|
|
{ |
81
|
|
|
$lib = $this->getDirLib(); |
82
|
|
|
$this->assertFalse($lib->copyDir(['next_one', 'sub_one'], ['next_one', 'sub_one', 'deeper'])); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @throws FilesException |
87
|
|
|
* @throws PathsException |
88
|
|
|
*/ |
89
|
|
|
public function testMove(): void |
90
|
|
|
{ |
91
|
|
|
$lib = $this->getDirFailLib(); |
92
|
|
|
$this->expectException(FilesException::class); |
93
|
|
|
$lib->moveDir(['more'], ['another']); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @throws FilesException |
98
|
|
|
* @throws PathsException |
99
|
|
|
*/ |
100
|
|
|
public function testMoveUnknown(): void |
101
|
|
|
{ |
102
|
|
|
$lib = $this->getDirLib(); |
103
|
|
|
$this->assertFalse($lib->moveDir(['not source'], ['extra2'])); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @throws FilesException |
108
|
|
|
* @throws PathsException |
109
|
|
|
*/ |
110
|
|
|
public function testMoveToUnknownDir(): void |
111
|
|
|
{ |
112
|
|
|
$lib = $this->getDirLib(); |
113
|
|
|
$this->assertFalse($lib->moveDir(['next_one', 'sub_one'], ['unknown', 'last_one'])); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @throws FilesException |
118
|
|
|
* @throws PathsException |
119
|
|
|
*/ |
120
|
|
|
public function testMoveToExisting(): void |
121
|
|
|
{ |
122
|
|
|
$lib = $this->getDirLib(); |
123
|
|
|
$this->assertFalse($lib->moveDir(['next_one', 'sub_one'], ['last_one'])); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @throws FilesException |
128
|
|
|
* @throws PathsException |
129
|
|
|
*/ |
130
|
|
|
public function testMoveToSub(): void |
131
|
|
|
{ |
132
|
|
|
$lib = $this->getDirLib(); |
133
|
|
|
$this->assertFalse($lib->moveDir(['next_one', 'sub_one'], ['next_one', 'sub_one', 'deeper'])); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @throws FilesException |
138
|
|
|
* @throws PathsException |
139
|
|
|
*/ |
140
|
|
|
public function testDelete(): void |
141
|
|
|
{ |
142
|
|
|
$lib = $this->getDirFailLib(); |
143
|
|
|
$this->expectException(FilesException::class); |
144
|
|
|
$lib->deleteDir(['another'], true); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @throws FilesException |
149
|
|
|
* @throws PathsException |
150
|
|
|
*/ |
151
|
|
|
public function testDeleteFile(): void |
152
|
|
|
{ |
153
|
|
|
$lib = $this->getDirLib(); |
154
|
|
|
$this->assertFalse($lib->deleteDir(['sub', 'dummy3.txt'])); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @throws FilesException |
159
|
|
|
* @throws PathsException |
160
|
|
|
*/ |
161
|
|
|
public function testDeleteNonEmpty(): void |
162
|
|
|
{ |
163
|
|
|
$lib = $this->getDirLib(); |
164
|
|
|
$this->assertFalse($lib->deleteDir(['next_one'])); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @throws FilesException |
169
|
|
|
* @throws PathsException |
170
|
|
|
*/ |
171
|
|
|
public function testDeepDeleteFail(): void |
172
|
|
|
{ |
173
|
|
|
$lib = $this->getDirLib(); |
174
|
|
|
$this->assertTrue($lib->createDir(['some', 'more'], true)); |
175
|
|
|
$this->assertFalse($lib->deleteDir(['some'])); |
176
|
|
|
$this->assertTrue($lib->deleteDir(['some'], true)); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|