|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Marcin. |
|
4
|
|
|
* Date: 03.03.2019 |
|
5
|
|
|
* Time: 17:07 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Tests\Mrcnpdlk\Api\Unoconv; |
|
9
|
|
|
|
|
10
|
|
|
use Mrcnpdlk\Api\Unoconv\Api; |
|
11
|
|
|
use Mrcnpdlk\Api\Unoconv\Config; |
|
12
|
|
|
use Mrcnpdlk\Api\Unoconv\Enum\FormatType; |
|
13
|
|
|
use Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException; |
|
14
|
|
|
use Mrcnpdlk\Api\Unoconv\Exception\UnoconvException; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class ApiTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testConstruct_1(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$oApi = new Api(); |
|
|
|
|
|
|
25
|
|
|
$this->assertTrue(true); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception |
|
30
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception\ConfigurationException |
|
31
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException |
|
32
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testConstruct_invalid_1(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->expectException(UnoconvException::class); |
|
37
|
|
|
$config = new Config([ |
|
|
|
|
|
|
38
|
|
|
'binary' => '/some/binary/file', |
|
39
|
|
|
]); |
|
40
|
|
|
$oApi = new Api(); |
|
41
|
|
|
$testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.docx'; |
|
42
|
|
|
file_put_contents($testFile, null); |
|
43
|
|
|
$oApi->transcode($testFile, FormatType::PDF()); |
|
44
|
|
|
@unlink($testFile); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception |
|
49
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception\ConfigurationException |
|
50
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException |
|
51
|
|
|
* @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testConstruct_invalid_2(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->expectException(InvalidFileArgumentException::class); |
|
56
|
|
|
$config = new Config([ |
|
|
|
|
|
|
57
|
|
|
'binary' => '/some/binary/file', |
|
58
|
|
|
]); |
|
59
|
|
|
$oApi = new Api(); |
|
60
|
|
|
$oApi->transcode('foo_bar.test', FormatType::PDF()); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.