Passed
Push — master ( 1b1dbd...2b0006 )
by Petr
10:06
created

MockTargetFactory::getStorage()   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
use kalanis\kw_storage\Interfaces;
4
use kalanis\kw_storage\Storage;
5
6
7
class CommonTestClass extends \PHPUnit\Framework\TestCase
8
{
9
    protected function getTestDir(): string
10
    {
11
        return implode(DIRECTORY_SEPARATOR, [__DIR__, 'tmp']) . DIRECTORY_SEPARATOR;
12
    }
13
14
    protected function mockTestFile(): string
15
    {
16
        return $this->getTestDir() . 'testingFile.txt';
17
    }
18
}
19
20
21
class TargetMock implements \kalanis\kw_storage\Interfaces\IStorage
22
{
23
    public function check(string $key): bool
24
    {
25
        return true;
26
    }
27
28
    public function exists(string $key): bool
29
    {
30
        return false;
31
    }
32
33
    public function load(string $key)
34
    {
35
        return 'dummy mock';
36
    }
37
38
    public function save(string $key, $data, ?int $timeout = null): bool
39
    {
40
        return empty($timeout);
41
    }
42
43
    public function remove(string $key): bool
44
    {
45
        return false;
46
    }
47
48
    public function lookup(string $path): \Traversable
49
    {
50
        yield from [];
51
    }
52
53
    public function increment(string $key): bool
54
    {
55
        return true;
56
    }
57
58
    public function decrement(string $key): bool
59
    {
60
        return false;
61
    }
62
63
    public function removeMulti(array $keys): array
64
    {
65
        return [];
66
    }
67
}
68
69
70
class MockKey implements \kalanis\kw_storage\Interfaces\IKey
71
{
72
    public function fromSharedKey(string $key): string
73
    {
74
        return implode(DIRECTORY_SEPARATOR, [__DIR__, 'tmp', $key]);
75
    }
76
}
77
78
79
class MockKeyFactory extends Storage\Key\Factory
80
{
81
    public function getKey(Interfaces\IStorage $storage): Interfaces\IKey
82
    {
83
        return new MockKey();
84
    }
85
}
86
87
88
class MockTargetFactory extends Storage\Target\Factory
89
{
90
    public function getStorage($params): Interfaces\IStorage
91
    {
92
        return new \TargetMock();
93
    }
94
}
95