Passed
Push — master ( 1a6375...8f4058 )
by Petr
08:21 queued 05:12
created

DataFilesTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 16
c 0
b 0
f 0
dl 0
loc 49
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getProcessor() 0 4 1
A fullProvider() 0 5 1
A testCannotMime() 0 5 1
A testFull() 0 5 1
A testCannotUseSource() 0 4 1
A testCannotUseMime() 0 4 1
1
<?php
2
3
namespace tests\ChecksTests;
4
5
6
use tests\CommonTestClass;
7
use kalanis\kw_files\Interfaces\IProcessFiles;
8
use kalanis\kw_files\Processing\Storage\Files\Basic;
9
use kalanis\kw_mime\Check\DataFiles;
10
use kalanis\kw_mime\MimeException;
11
use kalanis\kw_storage\Storage;
12
13
14
class DataFilesTest extends CommonTestClass
15
{
16
    public function testCannotUseMime(): void
17
    {
18
        $lib = new XFDataFiles();
19
        $this->assertFalse($lib->canUse('whatever'));
20
    }
21
22
    public function testCannotUseSource(): void
23
    {
24
        $lib = new DataFiles();
25
        $this->assertFalse($lib->canUse('whatever'));
26
    }
27
28
    /**
29
     * @throws MimeException
30
     */
31
    public function testCannotMime(): void
32
    {
33
        $lib = new XFDataFiles();
34
        $this->expectException(MimeException::class);
35
        $lib->getMime(['whatever']);
36
    }
37
38
    /**
39
     * @param string $file
40
     * @param string $mime
41
     * @throws MimeException
42
     * @dataProvider fullProvider
43
     */
44
    public function testFull(string $file, string $mime): void
45
    {
46
        $lib = new DataFiles();
47
        $lib->canUse($this->getProcessor());
48
        $this->assertEquals($mime, $lib->getMime([$file]));
49
    }
50
51
    public function fullProvider(): array
52
    {
53
        return [
54
            ['test.class', $this->defaultJavaFileMime()],
55
            ['test.pas', 'text/plain'],
56
        ];
57
    }
58
59
    protected function getProcessor(): IProcessFiles
60
    {
61
        Storage\Key\StaticPrefixKey::setPrefix(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR);
62
        return new Basic(new Storage\Storage(new Storage\Key\StaticPrefixKey(), new Storage\Target\Volume()));
63
    }
64
}
65