ApiTest::testConstruct_1()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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\DomainException;
14
use Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException;
15
use Mrcnpdlk\Api\Unoconv\Exception\UnoconvException;
16
use PHPUnit\Framework\TestCase;
17
use Psr\Log\NullLogger;
18
19
class ApiTest extends TestCase
20
{
21
    /**
22
     * @throws \Mrcnpdlk\Lib\ConfigurationException
23
     */
24
    public function testConstruct_1(): void
25
    {
26
        $oApi = new Api();
0 ignored issues
show
Unused Code introduced by
The assignment to $oApi is dead and can be removed.
Loading history...
27
        $this->assertTrue(true);
28
    }
29
30
    /**
31
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\DomainException
32
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
33
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
34
     * @throws \Mrcnpdlk\Lib\ConfigurationException
35
     */
36
    public function testConstruct_invalid_1(): void
37
    {
38
        $this->expectException(UnoconvException::class);
39
        $config   = new Config([
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
40
            'binary' => '/some/binary/file',
41
        ]);
42
        $oApi     = new Api();
43
        $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.docx';
44
        file_put_contents($testFile, null);
45
        $oApi->transcode($testFile, FormatType::PDF(), null);
46
        @unlink($testFile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

46
        /** @scrutinizer ignore-unhandled */ @unlink($testFile);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
47
    }
48
49
    /**
50
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\DomainException
51
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
52
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
53
     * @throws \Mrcnpdlk\Lib\ConfigurationException
54
     */
55
    public function testConstruct_invalid_2(): void
56
    {
57
        $this->expectException(InvalidFileArgumentException::class);
58
        $config = new Config([
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
59
            'binary' => '/some/binary/file',
60
        ]);
61
        $oApi   = new Api();
62
        $oApi->transcode('foo_bar.test', FormatType::PDF(), null);
63
    }
64
65
    /**
66
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\DomainException
67
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
68
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
69
     * @throws \Mrcnpdlk\Lib\ConfigurationException
70
     */
71
    public function testConstruct_invalid_3(): void
72
    {
73
        $this->expectException(DomainException::class);
74
        $config   = new Config([
75
            'binary' => '/some/binary/file',
76
            'logger' => new NullLogger(),
77
        ]);
78
        $oApi     = new Api($config);
79
        $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.docx';
80
        file_put_contents($testFile, null);
81
        $oApi->transcode($testFile, FormatType::PDF(), sys_get_temp_dir(), [
82
            'foo_bar' => null,
83
        ]);
84
        @unlink($testFile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

84
        /** @scrutinizer ignore-unhandled */ @unlink($testFile);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
85
    }
86
87
    /**
88
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\DomainException
89
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
90
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
91
     * @throws \Mrcnpdlk\Lib\ConfigurationException
92
     */
93
    public function testConstruct_invalid_4(): void
94
    {
95
        $this->expectException(UnoconvException::class);
96
97
        $oApi     = new Api();
98
        $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.docx';
99
        file_put_contents($testFile, null);
100
        $oApi->transcode($testFile, FormatType::PDF(), sys_get_temp_dir(), [
101
            'foo_string' => 'foo',
102
            'foo_bool'   => true,
103
        ]);
104
        @unlink($testFile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

104
        /** @scrutinizer ignore-unhandled */ @unlink($testFile);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
105
    }
106
107
    /**
108
     * @throws \Mrcnpdlk\Api\Unoconv\Exception
109
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
110
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
111
     * @throws \Mrcnpdlk\Lib\ConfigurationException
112
     */
113
    public function testWs_invalid_1(): void
114
    {
115
        $this->expectException(UnoconvException::class);
116
117
        $oApi     = new Api();
118
        $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.docx';
119
        file_put_contents($testFile, null);
120
        $oApi->wsGetPdf($testFile, sys_get_temp_dir());
121
        @unlink($testFile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

121
        /** @scrutinizer ignore-unhandled */ @unlink($testFile);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
122
    }
123
}
124