1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CheckTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_mime\Check\LocalVolume1; |
8
|
|
|
use kalanis\kw_mime\Check\LocalVolume2; |
9
|
|
|
use kalanis\kw_mime\MimeException; |
10
|
|
|
use kalanis\kw_paths\PathsException; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class LocalVolumeTest extends CommonTestClass |
14
|
|
|
{ |
15
|
|
|
public function testCannotUseMime1(): void |
16
|
|
|
{ |
17
|
|
|
$lib = new XFLocalVolume11(); |
18
|
|
|
$this->assertFalse($lib->canUse('whatever')); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testCannotUseMime2(): void |
22
|
|
|
{ |
23
|
|
|
$lib = new XFLocalVolume21(); |
24
|
|
|
$this->assertFalse($lib->canUse('whatever')); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testCannotUseSource(): void |
28
|
|
|
{ |
29
|
|
|
$lib = new LocalVolume1(); |
30
|
|
|
$this->assertFalse($lib->canUse(null)); |
31
|
|
|
$this->assertFalse($lib->canUse(fopen('php://memory', 'r+'))); |
32
|
|
|
$this->assertFalse($lib->canUse('not-a-known-path')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @throws MimeException |
37
|
|
|
*/ |
38
|
|
|
public function testCannotMime1(): void |
39
|
|
|
{ |
40
|
|
|
$lib = new XFLocalVolume12(); |
41
|
|
|
$this->expectException(MimeException::class); |
42
|
|
|
$this->expectExceptionMessage('mock 1'); |
43
|
|
|
$lib->getMime(['whatever']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @throws MimeException |
48
|
|
|
*/ |
49
|
|
|
public function testCannotMime2(): void |
50
|
|
|
{ |
51
|
|
|
$lib = new XFLocalVolume22(); |
52
|
|
|
$this->expectException(MimeException::class); |
53
|
|
|
$this->expectExceptionMessage('mock 2'); |
54
|
|
|
$lib->getMime(['whatever']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $file |
59
|
|
|
* @param string $mime |
60
|
|
|
* @throws MimeException |
61
|
|
|
* @dataProvider fullProvider1 |
62
|
|
|
*/ |
63
|
|
|
public function testFull1(string $file, string $mime): void |
64
|
|
|
{ |
65
|
|
|
$lib = new LocalVolume1(); |
66
|
|
|
$lib->canUse(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'); |
67
|
|
|
$this->assertEquals($mime, $lib->getMime([$file])); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $file |
72
|
|
|
* @param string $mime |
73
|
|
|
* @throws MimeException |
74
|
|
|
* @dataProvider fullProvider2 |
75
|
|
|
*/ |
76
|
|
|
public function testFull2(string $file, string $mime): void |
77
|
|
|
{ |
78
|
|
|
$lib = new LocalVolume2(); |
79
|
|
|
$lib->canUse(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'); |
80
|
|
|
$this->assertEquals($mime, $lib->getMime([$file])); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function fullProvider1(): array |
84
|
|
|
{ |
85
|
|
|
return [ |
86
|
|
|
['test.class', 'text/x-c'], |
87
|
|
|
['test.pas', 'text/plain'], |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function fullProvider2(): array |
92
|
|
|
{ |
93
|
|
|
return [ |
94
|
|
|
['test.class', 'text/plain; charset=us-ascii'], |
95
|
|
|
['test.pas', 'text/plain; charset=us-ascii'], |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
class XFLocalVolume11 extends LocalVolume1 |
102
|
|
|
{ |
103
|
|
|
public function isMimeFunction(): bool |
104
|
|
|
{ |
105
|
|
|
return false; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
class XFLocalVolume21 extends LocalVolume2 |
111
|
|
|
{ |
112
|
|
|
public function isMimeClass(): bool |
113
|
|
|
{ |
114
|
|
|
return false; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
class XFLocalVolume12 extends LocalVolume1 |
120
|
|
|
{ |
121
|
|
|
/** |
122
|
|
|
* @param string[] $path |
123
|
|
|
* @throws PathsException |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
protected function pathOnVolume(array $path): string |
127
|
|
|
{ |
128
|
|
|
throw new PathsException('mock 1'); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
class XFLocalVolume22 extends LocalVolume2 |
134
|
|
|
{ |
135
|
|
|
/** |
136
|
|
|
* @param string[] $path |
137
|
|
|
* @throws PathsException |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
protected function pathOnVolume(array $path): string |
141
|
|
|
{ |
142
|
|
|
throw new PathsException('mock 2'); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|