Completed
Pull Request — master (#304)
by Enrico
02:50
created

ObjectCastTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

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