1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace StorageDirsTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class FileTest extends AStorageTest |
10
|
|
|
{ |
11
|
|
|
protected function tearDown(): void |
12
|
|
|
{ |
13
|
|
|
if (is_file($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra.txt')) { |
14
|
|
|
unlink($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra.txt'); |
15
|
|
|
} |
16
|
|
|
if (is_file($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra1.txt')) { |
17
|
|
|
unlink($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra1.txt'); |
18
|
|
|
} |
19
|
|
|
if (is_file($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra2.txt')) { |
20
|
|
|
unlink($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra2.txt'); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @throws FilesException |
26
|
|
|
*/ |
27
|
|
|
public function testRead(): void |
28
|
|
|
{ |
29
|
|
|
$lib = $this->getFileLib(); |
30
|
|
|
$this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt'])); |
31
|
|
|
$this->assertEquals('asdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt'], 10)); |
32
|
|
|
$this->assertEquals('asdfghjkly', $lib->readFile(['dummy2.txt'], 10, 10)); |
33
|
|
|
$this->assertEquals('qwertzuiop', $lib->readFile(['dummy2.txt'], null, 10)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @throws FilesException |
38
|
|
|
*/ |
39
|
|
|
public function testReadNonExist(): void |
40
|
|
|
{ |
41
|
|
|
$lib = $this->getFileLib(); |
42
|
|
|
$this->expectException(FilesException::class); |
43
|
|
|
$lib->readFile(['unknown']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @throws FilesException |
48
|
|
|
*/ |
49
|
|
|
public function testSave(): void |
50
|
|
|
{ |
51
|
|
|
$lib = $this->getFileLib(); |
52
|
|
|
$this->assertTrue($lib->saveFile(['extra.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws FilesException |
57
|
|
|
*/ |
58
|
|
|
public function testCopyMoveDelete(): void |
59
|
|
|
{ |
60
|
|
|
$lib = $this->getFileLib(); |
61
|
|
|
$this->assertTrue($lib->copyFile(['dummy2.txt'], ['extra1.txt'])); |
62
|
|
|
$this->assertTrue($lib->moveFile(['extra1.txt'], ['extra2.txt'])); |
63
|
|
|
$this->assertTrue($lib->deleteFile(['extra2.txt'])); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|