1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace StorageBasicTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class FileTest extends AStorageTest |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @throws FilesException |
13
|
|
|
*/ |
14
|
|
|
public function testRead(): void |
15
|
|
|
{ |
16
|
|
|
$lib = $this->getFileLib(); |
17
|
|
|
$this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt'])); |
18
|
|
|
$this->assertEquals('asdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt'], 10)); |
19
|
|
|
$this->assertEquals('asdfghjkly', $lib->readFile(['dummy2.txt'], 10, 10)); |
20
|
|
|
$this->assertEquals('qwertzuiop', $lib->readFile(['dummy2.txt'], null, 10)); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @throws FilesException |
25
|
|
|
*/ |
26
|
|
|
public function testReadStream(): void |
27
|
|
|
{ |
28
|
|
|
$lib = $this->getFileLib(); |
29
|
|
|
$this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $this->streamToString($lib->readFile(['other1.txt']))); |
30
|
|
|
$this->assertEquals('asdfghjklyxcvbnm0123456789', $this->streamToString($lib->readFile(['other1.txt'], 10))); |
31
|
|
|
$this->assertEquals('asdfghjkly', $this->streamToString($lib->readFile(['other1.txt'], 10, 10))); |
32
|
|
|
$this->assertEquals('qwertzuiop', $this->streamToString($lib->readFile(['other1.txt'], null, 10))); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function streamToString($stream): string |
36
|
|
|
{ |
37
|
|
|
rewind($stream); |
38
|
|
|
return stream_get_contents($stream); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @throws FilesException |
43
|
|
|
*/ |
44
|
|
|
public function testReadNonExist(): void |
45
|
|
|
{ |
46
|
|
|
$lib = $this->getFileLib(); |
47
|
|
|
$this->expectException(FilesException::class); |
48
|
|
|
$lib->readFile(['unknown']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @throws FilesException |
53
|
|
|
*/ |
54
|
|
|
public function testReadFalse(): void |
55
|
|
|
{ |
56
|
|
|
$lib = $this->getFileLib(); |
57
|
|
|
$this->expectException(FilesException::class); |
58
|
|
|
$lib->readFile(['sub', 'dummy4.txt']); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @throws FilesException |
63
|
|
|
*/ |
64
|
|
|
public function testSave(): void |
65
|
|
|
{ |
66
|
|
|
$lib = $this->getFileLib(); |
67
|
|
|
$this->assertTrue($lib->saveFile(['extra.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @throws FilesException |
72
|
|
|
*/ |
73
|
|
|
public function testCopyMoveDelete(): void |
74
|
|
|
{ |
75
|
|
|
$lib = $this->getFileLib(); |
76
|
|
|
$this->assertTrue($lib->copyFile(['dummy2.txt'], ['extra1.txt'])); |
77
|
|
|
$this->assertTrue($lib->moveFile(['extra1.txt'], ['extra2.txt'])); |
78
|
|
|
$this->assertTrue($lib->deleteFile(['extra2.txt'])); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|