Passed
Push — master ( 1f33ad...fba3db )
by Petr
08:38
created

FileTest::testSave2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace StorageDirsTests;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_paths\PathsException;
8
9
10
class FileTest extends AStorageTest
11
{
12
    protected function tearDown(): void
13
    {
14
        if (is_file($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra.txt')) {
15
            unlink($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra.txt');
16
        }
17
        if (is_file($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra1.txt')) {
18
            unlink($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra1.txt');
19
        }
20
        if (is_file($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra2.txt')) {
21
            unlink($this->getTestPath() . DIRECTORY_SEPARATOR . 'extra2.txt');
22
        }
23
    }
24
25
    /**
26
     * @throws FilesException
27
     * @throws PathsException
28
     */
29
    public function testRead(): void
30
    {
31
        $lib = $this->getFileLib();
32
        $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt']));
33
        $this->assertEquals('asdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt'], 10));
34
        $this->assertEquals('asdfghjkly', $lib->readFile(['dummy2.txt'], 10, 10));
35
        $this->assertEquals('qwertzuiop', $lib->readFile(['dummy2.txt'], null, 10));
36
    }
37
38
    /**
39
     * @throws FilesException
40
     * @throws PathsException
41
     */
42
    public function testReadNonExist(): void
43
    {
44
        $lib = $this->getFileLib();
45
        $this->expectException(FilesException::class);
46
        $lib->readFile(['unknown']);
47
    }
48
49
    /**
50
     * @throws FilesException
51
     * @throws PathsException
52
     */
53
    public function testSave(): void
54
    {
55
        $lib = $this->getFileLib();
56
        $this->assertTrue($lib->saveFile(['extra.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789'));
57
    }
58
59
    /**
60
     * Insert content
61
     * @throws FilesException
62
     * @throws PathsException
63
     */
64
    public function testSave2(): void
65
    {
66
        $lib = $this->getFileLib();
67
        $this->assertTrue($lib->saveFile(['extra1.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789'));
68
        $this->assertTrue($lib->saveFile(['extra1.txt'], '0123456789', 15));
69
    }
70
71
    /**
72
     * Create file with moved content
73
     * @throws FilesException
74
     * @throws PathsException
75
     */
76
    public function testSave3(): void
77
    {
78
        $lib = $this->getFileLib();
79
        $this->assertTrue($lib->saveFile(['extra2.txt'], 'qwertzuiopasdfgh01234567890123456789', 5));
80
    }
81
82
    /**
83
     * @throws FilesException
84
     * @throws PathsException
85
     */
86
    public function testCopyMoveDelete(): void
87
    {
88
        $lib = $this->getFileLib();
89
        $this->assertTrue($lib->copyFile(['dummy2.txt'], ['extra1.txt']));
90
        $this->assertTrue($lib->moveFile(['extra1.txt'], ['extra2.txt']));
91
        $this->assertTrue($lib->deleteFile(['extra2.txt']));
92
    }
93
}
94