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

XFLocalVolume12   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 10
rs 10
wmc 1
1
<?php
2
3
namespace tests\ChecksTests;
4
5
6
use tests\CommonTestClass;
7
use kalanis\kw_mime\Check\LocalVolume1;
8
use kalanis\kw_mime\Check\LocalVolume2;
9
use kalanis\kw_mime\MimeException;
10
11
12
class LocalVolumeTest extends CommonTestClass
13
{
14
    public function testCannotUseMime1(): void
15
    {
16
        $lib = new XFLocalVolume11();
17
        $this->assertFalse($lib->canUse('whatever'));
18
    }
19
20
    public function testCannotUseMime2(): void
21
    {
22
        $lib = new XFLocalVolume21();
23
        $this->assertFalse($lib->canUse('whatever'));
24
    }
25
26
    public function testCannotUseSource(): void
27
    {
28
        $lib = new LocalVolume1();
29
        $this->assertFalse($lib->canUse(null));
30
        $this->assertFalse($lib->canUse(fopen('php://memory', 'r+')));
31
        $this->assertFalse($lib->canUse('not-a-known-path'));
32
    }
33
34
    /**
35
     * @throws MimeException
36
     */
37
    public function testCannotMime1(): void
38
    {
39
        $lib = new XFLocalVolume12();
40
        $this->expectExceptionMessage('mock 1');
41
        $this->expectException(MimeException::class);
42
        $lib->getMime(['whatever']);
43
    }
44
45
    /**
46
     * @throws MimeException
47
     */
48
    public function testCannotMime2(): void
49
    {
50
        $lib = new XFLocalVolume22();
51
        $this->expectExceptionMessage('mock 2');
52
        $this->expectException(MimeException::class);
53
        $lib->getMime(['whatever']);
54
    }
55
56
    /**
57
     * @param string $file
58
     * @param string $mime
59
     * @throws MimeException
60
     * @dataProvider fullProvider1
61
     */
62
    public function testFull1(string $file, string $mime): void
63
    {
64
        $lib = new LocalVolume1();
65
        $lib->canUse(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data');
66
        $this->assertEquals($mime, $lib->getMime([$file]));
67
    }
68
69
    /**
70
     * @param string $file
71
     * @param string $mime
72
     * @throws MimeException
73
     * @dataProvider fullProvider2
74
     */
75
    public function testFull2(string $file, string $mime): void
76
    {
77
        $lib = new LocalVolume2();
78
        $lib->canUse(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data');
79
        $this->assertEquals($mime, $lib->getMime([$file]));
80
    }
81
82
    public function fullProvider1(): array
83
    {
84
        return [
85
            ['test.class', $this->defaultJavaFileMime()],
86
            ['test.pas', 'text/plain'],
87
        ];
88
    }
89
90
    public function fullProvider2(): array
91
    {
92
        return [
93
            ['test.class', 'text/plain; charset=us-ascii'],
94
            ['test.pas', 'text/plain; charset=us-ascii'],
95
        ];
96
    }
97
}
98