Passed
Push — master ( c69355...293396 )
by Marcin
36s
created

ApiTest::testConstruct_invalid_3()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
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\Api\Unoconv\Exception
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
32
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\ConfigurationException
33
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
34
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
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
51
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\ConfigurationException
52
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
53
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
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
67
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\ConfigurationException
68
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\DomainException
69
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
70
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
71
     */
72
    public function testConstruct_invalid_3(): void
73
    {
74
        $this->expectException(DomainException::class);
75
        $config   = new Config([
76
            'binary' => '/some/binary/file',
77
            'logger' => new NullLogger(),
78
        ]);
79
        $oApi     = new Api($config);
80
        $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.docx';
81
        file_put_contents($testFile, null);
82
        $oApi->transcode($testFile, FormatType::PDF(), sys_get_temp_dir(), [
83
            'foo_bar' => null,
84
        ]);
85
        @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

85
        /** @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...
86
    }
87
88
    /**
89
     * @throws \Mrcnpdlk\Api\Unoconv\Exception
90
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\DomainException
91
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\InvalidFileArgumentException
92
     * @throws \Mrcnpdlk\Api\Unoconv\Exception\UnoconvException
93
     */
94
    public function testConstruct_invalid_4(): void
95
    {
96
        $this->expectException(UnoconvException::class);
97
98
        $oApi     = new Api();
99
        $testFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test.docx';
100
        file_put_contents($testFile, null);
101
        $oApi->transcode($testFile, FormatType::PDF(), sys_get_temp_dir(), [
102
            'foo_string' => 'foo',
103
            'foo_bool'   => true,
104
        ]);
105
        @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

105
        /** @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...
106
    }
107
}
108