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

StorageTest::testVolumeFileOperations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A StorageTest::testVolumeFileHarderCounter() 0 4 1
1
<?php
2
3
namespace BasicTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_storage\Helper;
8
use kalanis\kw_storage\Storage;
9
use kalanis\kw_storage\StorageException;
10
11
12
class StorageTest extends CommonTestClass
13
{
14
    /**
15
     * @throws StorageException
16
     */
17
    public function testStorageUninitialized(): void
18
    {
19
        $storage = new Storage($this->getStorageFactory());
20
        $this->expectException(StorageException::class);
21
        $storage->increment('abc');
22
    }
23
24
    /**
25
     * @throws StorageException
26
     */
27
    public function testStorageInitialized(): void
28
    {
29
        Helper::initStorage();
30
        $volume = $this->getStorageVolume();
31
        $this->assertTrue($volume->isConnected());
32
        $this->assertFalse($volume->exists('utz'));
33
    }
34
35
    /**
36
     * @throws StorageException
37
     */
38
    public function testOperations(): void
39
    {
40
        $volume = $this->getStorageVolume();
41
        $this->assertTrue($volume->set('abv', 'sdfhgdfh', null)); // must be empty timeout - enables in result - hack
42
        $this->assertTrue($volume->add('abv', 'dummy mock', null)); // must be same as in mock and have no timer - hack
43
        $this->assertEquals('dummy mock', $volume->get('abv'));
44
        $this->assertFalse($volume->add('abv', 'unknown', 354)); // must be different from mock
45
        $this->assertFalse($volume->delete('abv'));
46
    }
47
48
    /**
49
     * @throws StorageException
50
     */
51
    public function testLookup(): void
52
    {
53
        $volume = $this->getStorageVolume();
54
        $this->assertEmpty(iterator_to_array($volume->getAllKeys()));
55
    }
56
57
    /**
58
     * @throws StorageException
59
     */
60
    public function testVolumeFileCounter(): void
61
    {
62
        $volume = $this->getStorageVolume();
63
        $this->assertTrue($volume->increment($this->mockTestFile()));
64
        $this->assertFalse($volume->decrement($this->mockTestFile()));
65
    }
66
67
    /**
68
     * @throws StorageException
69
     */
70
    public function testVolumeFileHarderCounter(): void
71
    {
72
        $volume = $this->getStorageVolume();
73
        $this->assertEmpty($volume->deleteMulti(['dummyFile.tst']));
74
    }
75
76
    protected function getStorageVolume(): Storage
77
    {
78
        $storage = new Storage($this->getStorageFactory());
79
        $storage->init(null);
80
        return $storage;
81
    }
82
83
    protected function getStorageFactory(): Storage\Factory
84
    {
85
        return new Storage\Factory(new \MockKeyFactory(), new \MockTargetFactory());
86
    }
87
}
88