|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tests\ChecksTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use tests\CommonTestClass; |
|
7
|
|
|
use kalanis\kw_mime\Check\DataStorage; |
|
8
|
|
|
use kalanis\kw_mime\MimeException; |
|
9
|
|
|
use kalanis\kw_storage\Storage\Key; |
|
10
|
|
|
use kalanis\kw_storage\Storage; |
|
11
|
|
|
use kalanis\kw_storage\StorageException; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class DataStorageTest extends CommonTestClass |
|
15
|
|
|
{ |
|
16
|
|
|
public function testCannotUseMime(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$lib = new XFDataStorage1(); |
|
19
|
|
|
$this->assertFalse($lib->canUse('whatever')); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testCannotUseSource(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$lib = new DataStorage(); |
|
25
|
|
|
$this->assertFalse($lib->canUse('whatever')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @throws MimeException |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testCannotMime(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$lib = new XFDataStorage2(); |
|
34
|
|
|
$this->expectException(MimeException::class); |
|
35
|
|
|
$this->expectExceptionMessage('mock'); |
|
36
|
|
|
$lib->getMime(['whatever']); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $file |
|
41
|
|
|
* @param string $mime |
|
42
|
|
|
* @throws MimeException |
|
43
|
|
|
* @throws StorageException |
|
44
|
|
|
* @dataProvider fullProvider |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testFull(string $file, string $mime): void |
|
47
|
|
|
{ |
|
48
|
|
|
$lib = new DataStorage(); |
|
49
|
|
|
$lib->canUse($this->getProcessor()); |
|
50
|
|
|
$this->assertEquals($mime, $lib->getMime([$file])); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function fullProvider(): array |
|
54
|
|
|
{ |
|
55
|
|
|
return [ |
|
56
|
|
|
['test.class', $this->defaultJavaFileMime()], |
|
57
|
|
|
['test.pas', 'text/plain'], |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @throws StorageException |
|
63
|
|
|
* @return Storage |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function getProcessor(): Storage |
|
66
|
|
|
{ |
|
67
|
|
|
Key\StaticPrefixKey::setPrefix(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR); |
|
68
|
|
|
$lib = new Storage(new Storage\Factory(new Storage\Key\Factory(), new Storage\Target\Factory())); |
|
69
|
|
|
$lib->init('volume'); |
|
70
|
|
|
return $lib; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|