Passed
Push — master ( d309df...7ec489 )
by Petr
02:37
created

XCrashStorage::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace SourcesTests\Files\Storage;
4
5
6
use CommonTestClass;
7
use kalanis\kw_auth\AuthException;
8
use kalanis\kw_auth\Sources;
9
use kalanis\kw_storage\Interfaces\IStorage;
10
use kalanis\kw_storage\Storage\Key\DefaultKey;
11
use kalanis\kw_storage\Storage\Storage;
12
use kalanis\kw_storage\Storage\Target\Volume;
13
use kalanis\kw_storage\StorageException;
14
use Traversable;
15
16
17
abstract class AStorageTests extends CommonTestClass
18
{
19
    protected $sourcePath = '';
20
    protected $testingPath = '';
21
22
    protected function setUp(): void
23
    {
24
        $this->sourcePath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . '.groups';
25
        $this->testingPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . '.groups-duplicate';
26
    }
27
28
    protected function tearDown(): void
29
    {
30
        if (is_file($this->testingPath)) {
31
            unlink($this->testingPath);
32
        }
33
    }
34
}
35
36
37
class MockFiles
38
{
39
    use Sources\Files\Storage\TStorage;
40
    use Sources\Files\TLines;
41
42
    public function __construct(?IStorage $storage = null)
43
    {
44
        $this->storage = new Storage(new DefaultKey(), $storage ?: new Volume());
45
    }
46
47
    /**
48
     * @param string $path
49
     * @throws AuthException
50
     * @return string[][]
51
     */
52
    public function open(string $path): array
53
    {
54
        return $this->openFile($path);
55
    }
56
57
    /**
58
     * @param string $path
59
     * @param string[][] $content
60
     * @throws AuthException
61
     */
62
    public function save(string $path, array $content): void
63
    {
64
        $this->saveFile($path, $content);
65
    }
66
}
67
68
69
class XCrashStorage implements IStorage
70
{
71
    public function check(string $key): bool
72
    {
73
        return false;
74
    }
75
76
    public function exists(string $key): bool
77
    {
78
        return false;
79
    }
80
81
    public function load(string $key)
82
    {
83
        throw new StorageException('nope');
84
    }
85
86
    public function save(string $key, $data, ?int $timeout = null): bool
87
    {
88
        throw new StorageException('nope');
89
    }
90
91
    public function remove(string $key): bool
92
    {
93
        throw new StorageException('nope');
94
    }
95
96
    public function lookup(string $path): Traversable
97
    {
98
        throw new StorageException('nope');
99
    }
100
101
    public function increment(string $key): bool
102
    {
103
        throw new StorageException('nope');
104
    }
105
106
    public function decrement(string $key): bool
107
    {
108
        throw new StorageException('nope');
109
    }
110
111
    public function removeMulti(array $keys): array
112
    {
113
        throw new StorageException('nope');
114
    }
115
}
116