Passed
Push — master ( 7c550d...37ffb9 )
by Petr
02:16
created

KeysTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 26
rs 10
wmc 3
1
<?php
2
3
namespace BasicTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_storage\Storage\Key;
8
use kalanis\kw_storage\Storage\Target;
9
10
11
class KeysTest extends CommonTestClass
12
{
13
    public function testInit(): void
14
    {
15
        $factory = new Key\Factory();
16
        $this->assertInstanceOf(Key\DirKey::class, $factory->getKey(new Target\Volume()));
17
        $this->assertInstanceOf(Key\DirKey::class, $factory->getKey(new Target\VolumeTargetFlat()));
18
        $this->assertInstanceOf(Key\DirKey::class, $factory->getKey(new Target\VolumeStream()));
19
        $this->assertInstanceOf(Key\DefaultKey::class, $factory->getKey(new Target\Memory()));
20
        $this->assertInstanceOf(Key\DefaultKey::class, $factory->getKey(new \TargetMock()));
21
    }
22
23
    public function testDefaultKey(): void
24
    {
25
        $key = new Key\DefaultKey();
26
        $this->assertEquals('aaaaaaa', $key->fromSharedKey('aaaaaaa'));
27
        $this->assertEquals('ear/a4vw-z.7v2!3#z', $key->fromSharedKey('ear/a4vw-z.7v2!3#z'));
28
    }
29
30
    public function testDirKey(): void
31
    {
32
        $key = new Key\DirKey();
33
        $this->assertEquals('/var/cache/wwwcache/aaaaaaa', $key->fromSharedKey('aaaaaaa'));
34
        $key::setDir('/var/other/');
35
        $this->assertEquals('/var/other/ear/a4vw-z.7v2!3#z', $key->fromSharedKey('ear/a4vw-z.7v2!3#z'));
36
        $key::setDir('/var/cache/wwwcache/');
37
    }
38
}
39