Passed
Push — master ( cb2d88...e8a992 )
by Petr
08:25
created

XAccessFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
1
<?php
2
3
namespace ExtendedTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_files\Access\Factory;
8
use kalanis\kw_files\Extended\Config;
9
use kalanis\kw_files\Extended\Processor;
10
use kalanis\kw_files\FilesException;
11
use kalanis\kw_paths\PathsException;
12
use kalanis\kw_storage\Storage\Storage;
13
use kalanis\kw_storage\Storage\Key\DefaultKey;
14
use kalanis\kw_storage\Storage\Target\Memory;
15
16
17
class ProcessorTest extends CommonTestClass
18
{
19
    /**
20
     * @throws FilesException
21
     * @throws PathsException
22
     */
23
    public function testProcess(): void
24
    {
25
        $lib = new Processor(XAccessFactory::init()->getClass(new Storage(new DefaultKey(), new Memory())), new Config());
26
27
        $this->assertFalse($lib->exists(['foo', 'bar']));
28
        $this->assertFalse($lib->dirExists(['foo', 'bar']));
29
        $this->assertFalse($lib->fileExists(['foo', 'bar']));
30
        $this->assertTrue($lib->createDir(['foo', 'bar']));
31
        $this->assertTrue($lib->exists(['foo', 'bar']));
32
        $this->assertFalse($lib->fileExists(['foo', 'bar']));
33
        $this->assertTrue($lib->dirExists(['foo', 'bar']));
34
        $this->assertFalse($lib->exists(['foo', 'bar', '.txt']));
35
        $this->assertFalse($lib->createDir(['foo', 'bar'], true));
36
        $this->assertTrue($lib->makeExtended(['foo', 'bar']));
37
        $this->assertTrue($lib->exists(['foo', 'bar', '.txt']));
38
        $this->assertTrue($lib->dirExists(['foo', 'bar', '.txt']));
39
        $this->assertFalse($lib->fileExists(['foo', 'bar', '.txt']));
40
41
        $this->assertTrue($lib->removeExtended(['foo', 'bar']));
42
        $this->assertFalse($lib->exists(['foo', 'bar', '.txt']));
43
        $this->assertTrue($lib->removeDir(['foo', 'bar']));
44
        $this->assertFalse($lib->exists(['foo', 'bar']));
45
    }
46
47
    /**
48
     * @throws FilesException
49
     * @throws PathsException
50
     */
51
    public function testMakeThumbExists(): void
52
    {
53
        $config = new Config();
54
        $access = XAccessFactory::init()->getClass(new Storage(new DefaultKey(), new Memory()));
55
        $lib = new Processor($access, $config);
56
57
        $this->assertFalse($access->exists(['meek']));
58
        $this->assertTrue($lib->createDir(['meek']));
59
        $this->assertTrue($access->saveFile(['meek', $config->getThumbDir()], 'abcdef'));
60
        $this->assertFalse($lib->makeExtended(['meek']));
61
    }
62
63
    /**
64
     * @throws FilesException
65
     * @throws PathsException
66
     */
67
    public function testMakeDescExists(): void
68
    {
69
        $config = new Config();
70
        $access = XAccessFactory::init()->getClass(new Storage(new DefaultKey(), new Memory()));
71
        $lib = new Processor($access, $config);
72
73
        $this->assertFalse($access->exists(['meek']));
74
        $this->assertTrue($lib->createDir(['meek']));
75
        $this->assertTrue($access->saveFile(['meek', $config->getDescDir()], 'abcdef'));
76
        $this->assertFalse($lib->makeExtended(['meek']));
77
    }
78
79
    /**
80
     * @throws FilesException
81
     * @throws PathsException
82
     */
83
    public function testRemoveThumbExists(): void
84
    {
85
        $config = new Config();
86
        $access = XAccessFactory::init()->getClass(new Storage(new DefaultKey(), new Memory()));
87
        $lib = new Processor($access, $config);
88
89
        $this->assertFalse($access->exists(['meek']));
90
        $this->assertTrue($lib->createDir(['meek']));
91
        $this->assertTrue($access->saveFile(['meek', $config->getThumbDir()], 'abcdef'));
92
        $this->assertFalse($lib->removeExtended(['meek']));
93
    }
94
95
    /**
96
     * @throws FilesException
97
     * @throws PathsException
98
     */
99
    public function testRemoveDescExists(): void
100
    {
101
        $config = new Config();
102
        $storage = new Storage(new DefaultKey(), new Memory());
103
        $access = XAccessFactory::init()->getClass($storage);
104
        $lib = new Processor($access, $config);
105
106
        $this->assertFalse($access->exists(['meek']));
107
        $this->assertTrue($lib->createDir(['meek']));
108
        $this->assertTrue($access->saveFile(['meek', $config->getDescDir()], 'abcdef'));
109
        $this->assertFalse($lib->removeExtended(['meek']));
110
    }
111
}
112
113
114
class XAccessFactory extends Factory
115
{
116
    public static function init(): self
117
    {
118
        return new self();
119
    }
120
}
121