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\TempFiles; |
10
|
|
|
use kalanis\kw_mime\MimeException; |
11
|
|
|
use kalanis\kw_storage\Storage\Key; |
12
|
|
|
use kalanis\kw_storage\Storage\Storage; |
13
|
|
|
use kalanis\kw_storage\Storage\Target\Volume; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
class TempFilesTest extends CommonTestClass |
17
|
|
|
{ |
18
|
|
|
public function testCannotUseMime(): void |
19
|
|
|
{ |
20
|
|
|
$lib = new XFTempFiles1(); |
21
|
|
|
$this->assertFalse($lib->canUse('whatever')); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testCannotUseSource(): void |
25
|
|
|
{ |
26
|
|
|
$lib = new TempFiles(); |
27
|
|
|
$this->assertFalse($lib->canUse('whatever')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @throws MimeException |
32
|
|
|
*/ |
33
|
|
|
public function testCannotMime(): void |
34
|
|
|
{ |
35
|
|
|
$lib = new XFTempFiles2(); |
36
|
|
|
$this->expectException(MimeException::class); |
37
|
|
|
$lib->getMime(['whatever']); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $file |
42
|
|
|
* @param string $mime |
43
|
|
|
* @throws MimeException |
44
|
|
|
* @dataProvider fullProvider |
45
|
|
|
*/ |
46
|
|
|
public function testFull(string $file, string $mime): void |
47
|
|
|
{ |
48
|
|
|
$lib = new TempFiles(); |
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
|
|
|
protected function getProcessor(): IProcessFiles |
62
|
|
|
{ |
63
|
|
|
Key\StaticPrefixKey::setPrefix(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR); |
64
|
|
|
return new Basic(new Storage(new Key\StaticPrefixKey(), new Volume())); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|