Passed
Push — master ( b28c40...f61e74 )
by Petr
08:06
created

MockFiles   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 2
1
<?php
2
3
namespace SourcesTests\Files\Volume;
4
5
6
use CommonTestClass;
7
use kalanis\kw_auth\AuthException;
8
use kalanis\kw_auth\Sources;
9
10
11
class BasicTest extends CommonTestClass
12
{
13
    protected $sourcePath = '';
14
    protected $testingPath = '';
15
16
    protected function setUp(): void
17
    {
18
        $this->sourcePath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . '.groups';
19
        $this->testingPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . '.groups-duplicate';
20
    }
21
22
    protected function tearDown(): void
23
    {
24
        if (is_file($this->testingPath)) {
25
            unlink($this->testingPath);
26
        }
27
    }
28
29
    /**
30
     * @throws AuthException
31
     */
32
    public function testFiles(): void
33
    {
34
        $lib = new MockFiles();
35
        $content = $lib->open($this->sourcePath);
36
        $this->assertNotEmpty($content);
37
        $lib->save($this->testingPath, $content);
38
        chmod($this->testingPath, 0444);
39
        $this->expectException(AuthException::class);
40
        $lib->save($this->testingPath, $content);
41
    }
42
43
    /**
44
     * @throws AuthException
45
     */
46
    public function testFilesOpenCrash(): void
47
    {
48
        $lib = new MockFiles();
49
        $this->expectException(AuthException::class);
50
        $lib->open($this->testingPath);
51
    }
52
}
53
54
55
class MockFiles
56
{
57
    use Sources\Files\Volume\TVolume;
58
    use Sources\Files\TLines;
59
60
    /**
61
     * @param string $path
62
     * @throws AuthException
63
     * @return string[][]
64
     */
65
    public function open(string $path): array
66
    {
67
        return $this->openFile($path);
68
    }
69
70
    /**
71
     * @param string $path
72
     * @param string[][] $content
73
     * @throws AuthException
74
     */
75
    public function save(string $path, array $content): void
76
    {
77
        $this->saveFile($path, $content);
78
    }
79
}
80