|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tests\ChecksTests\TraitsTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use tests\CommonTestClass; |
|
7
|
|
|
use kalanis\kw_mime\MimeException; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class ToResourceTest extends CommonTestClass |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @throws MimeException |
|
14
|
|
|
*/ |
|
15
|
|
|
public function testNone1(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$lib = new XToResource(); |
|
18
|
|
|
$this->expectException(MimeException::class); |
|
19
|
|
|
$lib->convert('file', false); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @throws MimeException |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testNone2(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$lib = new XToResource(); |
|
28
|
|
|
$this->expectException(MimeException::class); |
|
29
|
|
|
$lib->convert('file', null); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @throws MimeException |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testString(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$lib = new XToResource(); |
|
38
|
|
|
$this->assertEquals('test data', stream_get_contents($lib->convert('data', 'test data'), -1, 0)); |
|
39
|
|
|
$this->assertEquals('123456', stream_get_contents($lib->convert('nums', 123456), -1, 0)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @throws MimeException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testResource(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$lib = new XToResource(); |
|
48
|
|
|
$res = @fopen('php://memory', 'r+'); |
|
49
|
|
|
fwrite($res, 'okmijnuhb'); |
|
|
|
|
|
|
50
|
|
|
$this->assertEquals('okmijnuhb', stream_get_contents($lib->convert('res', $res), -1, 0)); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|