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

TargetTest::testVolume()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.8333
1
<?php
2
3
namespace BasicTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_storage\Interfaces;
8
use kalanis\kw_storage\Storage;
9
use kalanis\kw_storage\StorageException;
10
11
12
class TargetTest extends CommonTestClass
13
{
14
    /**
15
     * @throws StorageException
16
     */
17
    public function testInit(): void
18
    {
19
        $factory = new Storage\Factory(new \MockKeyFactory(), new Storage\Target\Factory());
20
        $this->assertEmpty($factory->getStorage('none'));
21
    }
22
23
    /**
24
     * @throws StorageException
25
     */
26
    public function testVolume(): void
27
    {
28
        $factory = new Storage\Factory(new \MockKeyFactory(), new Storage\Target\Factory());
29
        $out1 = $factory->getStorage('volume');
30
        $this->assertInstanceOf(Interfaces\IPassDirs::class, $out1);
31
        $this->assertInstanceOf(Interfaces\IStorage::class, $out1);
32
        $this->assertFalse($out1->isFlat());
33
34
        $out2 = $factory->getStorage('volume::flat');
35
        $this->assertInstanceOf(Interfaces\IPassDirs::class, $out2);
36
        $this->assertInstanceOf(Interfaces\IStorage::class, $out2);
37
        $this->assertTrue($out2->isFlat());
38
39
        $out3 = $factory->getStorage(new \TargetMock());
40
        $this->assertFalse($out3 instanceof Interfaces\IPassDirs);
41
        $this->assertInstanceOf(Interfaces\IStorage::class, $out3);
42
        $this->assertFalse($out3->isFlat());
43
    }
44
45
    /**
46
     * @throws StorageException
47
     */
48
    public function testVolumeDir(): void
49
    {
50
        $volume = $this->getStorageVolume();
51
        // test file
52
        $this->assertTrue($volume->canUse());
53
        $this->assertFalse($volume->exists('dummyFile.tst'));
54
    }
55
56
    /**
57
     * @throws StorageException
58
     */
59
    public function testVolumeFileOperations(): void
60
    {
61
        $volume = $this->getStorageVolume();
62
        $this->assertTrue($volume->write('dummyFile.tst', 'asdfghjklpoiuztrewqyxcvbnm'));
63
        $this->assertEquals('dummy mock', $volume->read('dummyFile.tst'));
64
        $this->assertFalse($volume->remove('dummyFile.tst'));
65
    }
66
67
    /**
68
     * @throws StorageException
69
     */
70
    public function testVolumeFileLookup(): void
71
    {
72
        $volume = $this->getStorageVolume();
73
        $this->assertEmpty(iterator_to_array($volume->lookup('dummyFile')));
74
    }
75
76
    /**
77
     * @throws StorageException
78
     */
79
    public function testVolumeFileCounter(): void
80
    {
81
        $volume = $this->getStorageVolume();
82
        $this->assertTrue($volume->increment('dummyFile.tst'));
83
        $this->assertFalse($volume->decrement('dummyFile.tst'));
84
    }
85
86
    /**
87
     * @throws StorageException
88
     */
89
    public function testVolumeFileHarderCounter(): void
90
    {
91
        $volume = $this->getStorageVolume();
92
        $this->assertEmpty($volume->removeMulti(['dummyFile.tst']));
93
    }
94
95
    /**
96
     * @throws StorageException
97
     * @return Interfaces\IStorage
98
     */
99
    protected function getStorageVolume(): Interfaces\IStorage
100
    {
101
        return $this->getStorageFactory()->getStorage(null);
102
    }
103
104
    protected function getStorageFactory(): Storage\Factory
105
    {
106
        return new Storage\Factory(new \MockKeyFactory(), new \MockTargetFactory());
107
    }
108
}
109