Completed
Push — master ( 97ef1a...98c858 )
by Дмитрий
10:10
created

ObjectCastTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 92
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A objectCastDataProvider() 0 53 1
A testSuccessObjectCast() 0 14 1
A testUnknownType() 0 11 1
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\Casts;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
8
class ObjectCastTest extends \Tests\PHPSA\TestCase
9
{
10
    /**
11
     * Tests (object) {expr} = {expr}
12
     */
13
    public function objectCastDataProvider()
14
    {
15
        return [
16
            [
17
                CompiledExpression::INTEGER,
18
                1
19
            ],
20
            [
21
                CompiledExpression::DOUBLE,
22
                1.0
23
            ],
24
            [
25
                CompiledExpression::ARR,
26
                [
27
                    1,
28
                    2,
29
                    3,
30
                    4,
31
                    5
32
                ]
33
            ],
34
            [
35
                CompiledExpression::ARR,
36
                []
37
            ],
38
            [
39
                CompiledExpression::ARR,
40
                [
41
                    1,
42
                    2,
43
                    3,
44
                    4,
45
                    5
46
                ]
47
            ],
48
            [
49
                CompiledExpression::BOOLEAN,
50
                true
51
            ],
52
            [
53
                CompiledExpression::RESOURCE,
54
                STDIN
55
            ],
56
            [
57
                CompiledExpression::STRING,
58
                'test str'
59
            ],
60
            [
61
                CompiledExpression::NULL,
62
                null
63
            ],
64
        ];
65
    }
66
67
    /**
68
     * @dataProvider objectCastDataProvider
69
     *
70
     * @param int $type
71
     * @param mixed $value
72
     */
73
    public function testSuccessObjectCast($type, $value)
74
    {
75
        $baseExpression = new Node\Expr\Cast\Object_(
76
            $this->newFakeScalarExpr(
77
                $type,
78
                $value
79
            )
80
        );
81
        $compiledExpression = $this->compileExpression($baseExpression);
82
83
        $this->assertInstanceOfCompiledExpression($compiledExpression);
84
        $this->assertSame(CompiledExpression::OBJECT, $compiledExpression->getType());
85
        $this->assertEquals((object) $value, $compiledExpression->getValue());
86
    }
87
88
    public function testUnknownType()
89
    {
90
        $baseExpression = new Node\Expr\Cast\Object_(
91
            $this->newFakeScalarExpr()
92
        );
93
        $compiledExpression = $this->compileExpression($baseExpression);
94
95
        $this->assertInstanceOfCompiledExpression($compiledExpression);
96
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
97
        $this->assertSame(null, $compiledExpression->getValue());
98
    }
99
}
100