|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace StorageBasicTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
|
7
|
|
|
use kalanis\kw_paths\PathsException; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class FileFailTest extends AStorageTest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @throws FilesException |
|
14
|
|
|
* @throws PathsException |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testRead(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$lib = $this->getFileFailLib(); |
|
19
|
|
|
$this->expectException(FilesException::class); |
|
20
|
|
|
$lib->readFile(['dummy2.txt']); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @throws FilesException |
|
25
|
|
|
* @throws PathsException |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testSave(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$lib = $this->getFileFailLib(); |
|
30
|
|
|
$this->expectException(FilesException::class); |
|
31
|
|
|
$lib->saveFile(['extra.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @throws FilesException |
|
36
|
|
|
* @throws PathsException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testSave2(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$lib = $this->getFileFailLib(); |
|
41
|
|
|
$this->expectException(FilesException::class); |
|
42
|
|
|
$lib->saveFile([], 'qwertzuiopasdfghjklyxcvbnm0123456789'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @throws FilesException |
|
47
|
|
|
* @throws PathsException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testSave3(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$lib = $this->getFileLib(); |
|
52
|
|
|
$this->expectException(FilesException::class); |
|
53
|
|
|
$lib->saveFile(['not existent', 'directory', 'with file'], 'qwertzuiopasdfghjklyxcvbnm0123456789'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @throws FilesException |
|
58
|
|
|
* @throws PathsException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testCopy(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$lib = $this->getFileFailLib(); |
|
63
|
|
|
$this->expectException(FilesException::class); |
|
64
|
|
|
$lib->copyFile(['dummy2.txt'], ['extra1.txt']); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @throws FilesException |
|
69
|
|
|
* @throws PathsException |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testCopyToExisting(): void |
|
72
|
|
|
{ |
|
73
|
|
|
$lib = $this->getFileLib(); |
|
74
|
|
|
$this->assertFalse($lib->copyFile(['dummy2.txt'], ['dummy1.txt'])); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @throws FilesException |
|
79
|
|
|
* @throws PathsException |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testMove(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$lib = $this->getFileFailLib(); |
|
84
|
|
|
$this->expectException(FilesException::class); |
|
85
|
|
|
$lib->moveFile(['extra1.txt'], ['extra2.txt']); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @throws FilesException |
|
90
|
|
|
* @throws PathsException |
|
91
|
|
|
*/ |
|
92
|
|
|
public function testMoveUnknown(): void |
|
93
|
|
|
{ |
|
94
|
|
|
$lib = $this->getFileLib(); |
|
95
|
|
|
$this->expectException(FilesException::class); |
|
96
|
|
|
$lib->moveFile(['not source.txt'], ['extra2.txt']); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @throws FilesException |
|
101
|
|
|
* @throws PathsException |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testMoveToUnknownDir(): void |
|
104
|
|
|
{ |
|
105
|
|
|
$lib = $this->getFileLib(); |
|
106
|
|
|
$this->assertFalse($lib->moveFile(['sub', 'dummy3.txt'], ['whatabout', 'other2.txt'])); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @throws FilesException |
|
111
|
|
|
* @throws PathsException |
|
112
|
|
|
*/ |
|
113
|
|
|
public function testMoveToExisting(): void |
|
114
|
|
|
{ |
|
115
|
|
|
$lib = $this->getFileLib(); |
|
116
|
|
|
$this->assertFalse($lib->moveFile(['sub', 'dummy3.txt'], ['other2.txt'])); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @throws FilesException |
|
121
|
|
|
* @throws PathsException |
|
122
|
|
|
*/ |
|
123
|
|
|
public function testDelete(): void |
|
124
|
|
|
{ |
|
125
|
|
|
$lib = $this->getFileFailLib(); |
|
126
|
|
|
$this->expectException(FilesException::class); |
|
127
|
|
|
$lib->deleteFile(['extra2.txt']); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|