Passed
Push — master ( 544acf...309dcb )
by Petr
02:18
created

TargetTest::testVolume()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
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 10
rs 10
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
    public function testInit(): void
15
    {
16
        $factory = new Storage\Factory(new \MockKeyFactory(), new Storage\Target\Factory());
17
        $this->assertEmpty($factory->getStorage('none'));
18
    }
19
20
    public function testVolume(): void
21
    {
22
        $factory = new Storage\Factory(new \MockKeyFactory(), new Storage\Target\Factory());
23
        $out = $factory->getStorage('volume');
24
        $this->assertInstanceOf(Interfaces\IPassDirs::class, $out);
25
        $this->assertInstanceOf(Interfaces\IStorage::class, $out);
26
27
        $out = $factory->getStorage(new \TargetMock());
28
        $this->assertFalse($out instanceof Interfaces\IPassDirs);
29
        $this->assertInstanceOf(Interfaces\IStorage::class, $out);
30
    }
31
32
    /**
33
     * @throws StorageException
34
     */
35
    public function testVolumeDir(): void
36
    {
37
        $volume = $this->getStorageVolume();
38
        // test file
39
        $this->assertTrue($volume->canUse());
40
        $this->assertFalse($volume->exists('dummyFile.tst'));
41
    }
42
43
    /**
44
     * @throws StorageException
45
     */
46
    public function testVolumeFileOperations(): void
47
    {
48
        $volume = $this->getStorageVolume();
49
        $this->assertTrue($volume->write('dummyFile.tst', 'asdfghjklpoiuztrewqyxcvbnm'));
50
        $this->assertEquals('dummy mock', $volume->read('dummyFile.tst'));
51
        $this->assertFalse($volume->remove('dummyFile.tst'));
52
    }
53
54
    /**
55
     * @throws StorageException
56
     */
57
    public function testVolumeFileLookup(): void
58
    {
59
        $volume = $this->getStorageVolume();
60
        $this->assertEmpty(iterator_to_array($volume->lookup('dummyFile')));
61
    }
62
63
    /**
64
     * @throws StorageException
65
     */
66
    public function testVolumeFileCounter(): void
67
    {
68
        $volume = $this->getStorageVolume();
69
        $this->assertTrue($volume->increment('dummyFile.tst'));
70
        $this->assertFalse($volume->decrement('dummyFile.tst'));
71
    }
72
73
    /**
74
     * @throws StorageException
75
     */
76
    public function testVolumeFileHarderCounter(): void
77
    {
78
        $volume = $this->getStorageVolume();
79
        $this->assertEmpty($volume->removeMulti(['dummyFile.tst']));
80
    }
81
82
    protected function getStorageVolume(): Interfaces\IStorage
83
    {
84
        return $this->getStorageFactory()->getStorage(null);
85
    }
86
87
    protected function getStorageFactory(): Storage\Factory
88
    {
89
        return new Storage\Factory(new \MockKeyFactory(), new \MockTargetFactory());
90
    }
91
}
92