Test Failed
Push — master ( f9dc8e...64f7bc )
by Petr
08:10
created

DescTest::testProcessing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 33
rs 9.52
c 1
b 0
f 0
1
<?php
2
3
namespace SourcesTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_files\Access\Factory;
8
use kalanis\kw_files\Extended\Config;
9
use kalanis\kw_files\FilesException;
10
use kalanis\kw_images\Sources\Desc;
11
use kalanis\kw_paths\PathsException;
12
use kalanis\kw_storage\Storage\Key;
13
use kalanis\kw_storage\Storage\Target;
14
15
16
class DescTest extends CommonTestClass
17
{
18
    /**
19
     * @throws FilesException
20
     * @throws PathsException
21
     */
22
    public function testProcessing(): void
23
    {
24
        $lib = $this->getLib();
25
        $this->assertFalse($lib->isHere(['testtree', 'testimage.png']));
26
        $this->assertFalse($lib->isHere(['dumptree', 'tstimg.png']));
27
        $this->assertEmpty($lib->get(['testtree', 'testimage.png']));
28
        $this->assertEmpty($lib->get(['dumptree', 'tstimg.png']));
29
30
        $lib->set(['testtree', 'testimage.png'], static::TEST_STRING);
31
        $this->assertTrue($lib->isHere(['testtree', 'testimage.png']));
32
        $this->assertEquals(static::TEST_STRING, $lib->get(['testtree', 'testimage.png']));
33
34
        $this->assertTrue($lib->copy('testimage.png', ['testtree'], ['dumptree']));
35
        $this->assertEquals(static::TEST_STRING, $lib->get(['dumptree', 'testimage.png']));
36
37
        $this->assertTrue($lib->move('testimage.png', ['testtree'], ['dumptree'] ,true));
38
        $this->assertFalse($lib->isHere(['testtree', 'testimage.png']));
39
        $this->assertEmpty($lib->get(['testtree', 'testimage.png']));
40
41
        $this->assertTrue($lib->rename(['dumptree'], 'testimage.png', 'tstimg.png'));
42
        $this->assertEmpty($lib->get(['dumptree', 'testimage.png']));
43
        $this->assertTrue($lib->isHere(['dumptree', 'tstimg.png']));
44
        $this->assertEquals(static::TEST_STRING, $lib->get(['dumptree', 'tstimg.png']));
45
46
        $this->assertTrue($lib->delete(['dumptree'], 'tstimg.png'));
47
        $this->assertFalse($lib->isHere(['testtree', 'testimage.png']));
48
        $this->assertFalse($lib->isHere(['dumptree', 'tstimg.png']));
49
        $this->assertEmpty($lib->get(['testtree', 'testimage.png']));
50
        $this->assertEmpty($lib->get(['dumptree', 'testimage.png']));
51
        $this->assertEmpty($lib->get(['dumptree', 'tstimg.png']));
52
53
        $this->expectException(FilesException::class);
54
        $lib->get(['dumptree', 'tstimg.png'], true);
55
    }
56
57
    /**
58
     * @param array<string, string|int> $params
59
     * @throws FilesException
60
     * @throws PathsException
61
     * @return Desc
62
     */
63
    protected function getLib(array $params = [])
64
    {
65
        $storage = new \kalanis\kw_storage\Storage\Storage(new Key\DefaultKey(), new Target\Memory());
66
        return new Desc((new Factory())->getClass($storage), (new Config())->setData($params));
67
    }
68
}
69