Passed
Push — master ( 1a6375...8f4058 )
by Petr
08:21 queued 05:12
created

ToStringTest::testNone2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace tests\ChecksTests\TraitsTests;
4
5
6
use tests\CommonTestClass;
7
use kalanis\kw_mime\MimeException;
8
9
10
class ToStringTest extends CommonTestClass
11
{
12
    /**
13
     * @throws MimeException
14
     */
15
    public function testNone1(): void
16
    {
17
        $lib = new XToString();
18
        $this->expectException(MimeException::class);
19
        $lib->convert('file', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type resource|string expected by parameter $content of tests\ChecksTests\TraitsTests\XToString::convert(). ( Ignorable by Annotation )

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

19
        $lib->convert('file', /** @scrutinizer ignore-type */ false);
Loading history...
20
    }
21
22
    /**
23
     * @throws MimeException
24
     */
25
    public function testNone2(): void
26
    {
27
        $lib = new XToString();
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 XToString();
38
        $this->assertEquals('test data', $lib->convert('data', 'test data'));
39
        $this->assertEquals('123456', $lib->convert('nums', 123456));
40
    }
41
42
    /**
43
     * @throws MimeException
44
     */
45
    public function testResource(): void
46
    {
47
        $lib = new XToString();
48
        $res = @fopen('php://memory', 'r+');
49
        fwrite($res, 'okmijnuhb');
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type false; however, parameter $stream of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

49
        fwrite(/** @scrutinizer ignore-type */ $res, 'okmijnuhb');
Loading history...
50
        $this->assertEquals('okmijnuhb', $lib->convert('res', $res));
0 ignored issues
show
Bug introduced by
It seems like $res can also be of type false; however, parameter $content of tests\ChecksTests\TraitsTests\XToString::convert() does only seem to accept resource|string, maybe add an additional type check? ( Ignorable by Annotation )

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

50
        $this->assertEquals('okmijnuhb', $lib->convert('res', /** @scrutinizer ignore-type */ $res));
Loading history...
51
    }
52
}
53