Completed
Pull Request — master (#124)
by Enrico
04:04
created

ArrayTest::testArrayWith2IntValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
/**
10
 * Class ArrayTest
11
 * @package Tests\PHPSA\Expression
12
 */
13
class ArrayTest extends \Tests\PHPSA\TestCase
14
{
15
    /**
16
     * Tests {expr} = array();
17
     */
18
    public function testEmptyArray()
19
    {
20
        $baseExpression = new Node\Expr\Array_();
21
        $compiledExpression = $this->compileExpression($baseExpression, $this->getContext());
22
23
        $this->assertInstanceOfCompiledExpression($compiledExpression);
24
        $this->assertSame(CompiledExpression::ARR, $compiledExpression->getType());
25
        $this->assertSame(array(), $compiledExpression->getValue());
26
    }
27
28
    /**
29
     * Tests {expr} = array(1, 2, 3, 4, 5, 6);
30
     */
31
    public function testArrayWith6IntValues()
32
    {
33
        $compiledExpression = $this->compileExpression(
34
            new Node\Expr\Array_(
35
                array(
36
                    new Node\Expr\ArrayItem(
37
                        $this->newScalarExpr(1)
38
                    ),
39
                    new Node\Expr\ArrayItem(
40
                        $this->newScalarExpr(2)
41
                    ),
42
                    new Node\Expr\ArrayItem(
43
                        $this->newScalarExpr(3)
44
                    ),
45
                    new Node\Expr\ArrayItem(
46
                        $this->newScalarExpr(4)
47
                    ),
48
                    new Node\Expr\ArrayItem(
49
                        $this->newScalarExpr(5)
50
                    ),
51
                    new Node\Expr\ArrayItem(
52
                        $this->newScalarExpr(6)
53
                    )
54
                )
55
            ),
56
            $this->getContext()
57
        );
58
59
        $this->assertInstanceOfCompiledExpression($compiledExpression);
60
        $this->assertSame(CompiledExpression::ARR, $compiledExpression->getType());
61
        $this->assertSame(array(1, 2, 3, 4, 5, 6), $compiledExpression->getValue());
62
    }
63
64
    /**
65
     * Tests {expr} = array(1, 2);
66
     */
67
    public function testArrayWith2IntValues()
68
    {
69
        $compiledExpression = $this->compileExpression(
70
            new Node\Expr\Array_(
71
                array(
72
                    new Node\Expr\ArrayItem(
73
                        $this->newScalarExpr(1)
74
                    ),
75
                    new Node\Expr\ArrayItem(
76
                        $this->newScalarExpr(2)
77
                    )
78
                )
79
            ),
80
            $this->getContext()
81
        );
82
83
        $this->assertInstanceOfCompiledExpression($compiledExpression);
84
        $this->assertSame(CompiledExpression::ARR, $compiledExpression->getType());
85
        $this->assertSame(array(1, 2), $compiledExpression->getValue());
86
    }
87
88
    /**
89
     * Tests {expr} = array(...);
90
     */
91
    public function testArrayWith2StringIntExpr()
92
    {
93
        $compiledExpression = $this->compileExpression(
94
            new Node\Expr\Array_(
95
                array(
96
                    new Node\Expr\ArrayItem(
97
                        $this->newScalarExpr(1),
98
                        $this->newScalarExpr('key1')
99
                    ),
100
                    new Node\Expr\ArrayItem(
101
                        $this->newScalarExpr(2),
102
                        $this->newScalarExpr('key2')
103
                    )
104
                )
105
            ),
106
            $this->getContext()
107
        );
108
109
        $this->assertInstanceOfCompiledExpression($compiledExpression);
110
        $this->assertSame(CompiledExpression::ARR, $compiledExpression->getType());
111
        $this->assertSame(
112
            array(
113
                'key1' => 1,
114
                'key2' => 2
115
            ),
116
            $compiledExpression->getValue()
117
        );
118
    }
119
}
120