Passed
Push — master ( 728467...6349cc )
by Petr
07:23
created

ToStringTest::testSimple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace TraitsTests;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_files\Traits\TToString;
8
9
10
class ToStringTest extends \CommonTestClass
11
{
12
    /**
13
     * @param mixed $ext
14
     * @param string $result
15
     * @throws FilesException
16
     * @dataProvider filterDataProvider
17
     */
18
    public function testSimple($ext, string $result): void
19
    {
20
        $lib = new XToString();
21
        $this->assertEquals($result, $lib->toStr($ext));
22
    }
23
24
    public function filterDataProvider(): array
25
    {
26
        $stream1 = fopen('php://memory', 'r+');
27
        fwrite($stream1,'Just for unable read');
28
        return [
29
            [$stream1, 'Just for unable read'],
30
            ['there is no string', 'there is no string'],
31
            [123456, '123456'],
32
            [123.456, '123.456'],
33
            [new StrObj(), 'test'],
34
        ];
35
    }
36
37
    /**
38
     * @param mixed $ext
39
     * @throws FilesException
40
     * @dataProvider dieProvider
41
     */
42
    public function testDie($ext): void
43
    {
44
        $lib = new XToString();
45
        $this->expectException(FilesException::class);
46
        $lib->toStr($ext);
47
    }
48
49
    public function dieProvider(): array
50
    {
51
        return [
52
            [new \stdClass()],
53
            [true],
54
            [false],
55
            [null],
56
        ];
57
    }
58
}
59
60
61
class XToString
62
{
63
    use TToString;
64
65
    /**
66
     * @param mixed $content
67
     * @throws FilesException
68
     * @return string
69
     */
70
    public function toStr($content): string
71
    {
72
        return $this->toString('test', $content);
73
    }
74
}
75
76
77
class StrObj
78
{
79
    public function __toString(): string
80
    {
81
        return 'test';
82
    }
83
}