|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tests\ChecksTests\TraitsTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use tests\CommonTestClass; |
|
7
|
|
|
use kalanis\kw_mime\MimeException; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class ToLocalFileTest extends CommonTestClass |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @throws MimeException |
|
14
|
|
|
*/ |
|
15
|
|
|
public function testNone1(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$lib = new XToLocalFile(); |
|
18
|
|
|
$lib->initTempFile(); |
|
19
|
|
|
@unlink($lib->getTempFile()); |
|
|
|
|
|
|
20
|
|
|
$this->expectException(MimeException::class); |
|
21
|
|
|
$lib->convert('file', /** @scrutinizer ignore-type */ false); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @throws MimeException |
|
26
|
|
|
*/ |
|
27
|
|
|
public function testNone2(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$lib = new XToLocalFile(); |
|
30
|
|
|
$lib->initTempFile(); |
|
31
|
|
|
@unlink($lib->getTempFile()); |
|
|
|
|
|
|
32
|
|
|
$this->expectException(MimeException::class); |
|
33
|
|
|
$lib->convert('file', /** @scrutinizer ignore-type */ null); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @throws MimeException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testString(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$lib = new XToLocalFile(); |
|
42
|
|
|
$lib->initTempFile(); |
|
43
|
|
|
$pt1 = $lib->convert('data', 'test data'); |
|
44
|
|
|
$this->assertEquals('test data', file_get_contents($pt1)); |
|
45
|
|
|
@unlink($pt1); |
|
|
|
|
|
|
46
|
|
|
$lib->initTempFile(); |
|
47
|
|
|
$pt2 = $lib->convert('nums', /** @scrutinizer ignore-type */ 123456); |
|
48
|
|
|
$this->assertEquals('123456', file_get_contents($pt2)); |
|
49
|
|
|
@unlink($pt2); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @throws MimeException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testResource(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$lib = new XToLocalFile(); |
|
58
|
|
|
$res = @fopen('php://memory', 'r+'); |
|
59
|
|
|
fwrite($res, 'okmijnuhb'); |
|
|
|
|
|
|
60
|
|
|
$lib->initTempFile(); |
|
61
|
|
|
$pt1 = $lib->convert('res', $res); |
|
|
|
|
|
|
62
|
|
|
$this->assertEquals('okmijnuhb', file_get_contents($pt1)); |
|
63
|
|
|
@unlink($pt1); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: