FileTest   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 51
dl 0
loc 122
rs 10
c 2
b 0
f 0
wmc 12

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testSave() 0 12 2
A testReadFalse() 0 12 2
A testReadNonExist() 0 12 2
A testRead() 0 14 2
A testCopyMoveDelete() 0 14 2
A testSave2() 0 16 2
1
<?php
2
3
namespace MapperTests;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_mapper\MapperException;
8
use kalanis\kw_paths\PathsException;
9
10
11
class FileTest extends AStorageTest
12
{
13
    /**
14
     * @throws FilesException
15
     * @throws MapperException
16
     * @throws PathsException
17
     */
18
    public function testRead(): void
19
    {
20
        if ($this->skipIt) {
21
            $this->markTestSkipped('Skipped by config');
22
            return;
23
        }
24
25
        $this->dataRefill();
26
27
        $lib = $this->getFileLib();
28
        $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt']));
29
        $this->assertEquals('asdfghjklyxcvbnm0123456789', $lib->readFile(['dummy2.txt'], 10));
30
        $this->assertEquals('asdfghjkly', $lib->readFile(['dummy2.txt'], 10, 10));
31
        $this->assertEquals('qwertzuiop', $lib->readFile(['dummy2.txt'], null, 10));
32
    }
33
34
    /**
35
     * @throws FilesException
36
     * @throws MapperException
37
     * @throws PathsException
38
     */
39
    public function testReadNonExist(): void
40
    {
41
        if ($this->skipIt) {
42
            $this->markTestSkipped('Skipped by config');
43
            return;
44
        }
45
46
        $this->dataRefill();
47
48
        $lib = $this->getFileLib();
49
        $this->expectException(FilesException::class);
50
        $lib->readFile(['unknown']);
51
    }
52
53
    /**
54
     * @throws FilesException
55
     * @throws MapperException
56
     * @throws PathsException
57
     */
58
    public function testReadFalse(): void
59
    {
60
        if ($this->skipIt) {
61
            $this->markTestSkipped('Skipped by config');
62
            return;
63
        }
64
65
        $this->dataRefill();
66
67
        $lib = $this->getFileLib();
68
        $this->expectException(FilesException::class);
69
        $lib->readFile(['sub', 'dummy_nope.txt']);
70
    }
71
72
    /**
73
     * @throws FilesException
74
     * @throws MapperException
75
     * @throws PathsException
76
     */
77
    public function testSave(): void
78
    {
79
        if ($this->skipIt) {
80
            $this->markTestSkipped('Skipped by config');
81
            return;
82
        }
83
84
        $this->dataRefill();
85
86
        $lib = $this->getFileLib();
87
        $this->assertTrue($lib->saveFile(['extra.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789'));
88
        $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['extra.txt']));
89
    }
90
91
    /**
92
     * @throws FilesException
93
     * @throws MapperException
94
     * @throws PathsException
95
     */
96
    public function testSave2(): void
97
    {
98
        if ($this->skipIt) {
99
            $this->markTestSkipped('Skipped by config');
100
            return;
101
        }
102
103
        $this->dataRefill();
104
105
        $lib = $this->getFileLib();
106
        $this->assertTrue($lib->saveFile(['sub', 'foul.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789'));
107
        $this->assertEquals('qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['sub', 'foul.txt']));
108
        $this->assertTrue($lib->saveFile(['sub', 'foul.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789', 3));
109
        $this->assertEquals(chr(0) . chr(0) . chr(0) . 'qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['sub', 'foul.txt']));
110
        $this->assertTrue($lib->saveFile(['sub', 'foul.txt'], 'qwertzuiopasdfghjklyxcvbnm0123456789', 42, FILE_APPEND));
111
        $this->assertEquals(chr(0) . chr(0) . chr(0) . 'qwertzuiopasdfghjklyxcvbnm0123456789' . chr(0) . chr(0) . chr(0) . 'qwertzuiopasdfghjklyxcvbnm0123456789', $lib->readFile(['sub', 'foul.txt']));
112
    }
113
114
    /**
115
     * @throws FilesException
116
     * @throws MapperException
117
     * @throws PathsException
118
     */
119
    public function testCopyMoveDelete(): void
120
    {
121
        if ($this->skipIt) {
122
            $this->markTestSkipped('Skipped by config');
123
            return;
124
        }
125
126
        $this->dataRefill();
127
128
        $lib = $this->getFileLib();
129
        $this->assertTrue($lib->copyFile(['dummy2.txt'], ['extra1.txt']));
130
        $this->assertTrue($lib->moveFile(['extra1.txt'], ['extra2.txt']));
131
        $this->assertTrue($lib->deleteFile(['extra2.txt']));
132
        $this->assertTrue($lib->deleteFile(['extra3.txt']));
133
    }
134
}
135