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

ArrayCastTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 6 1
A testSimpleSuccessCompile() 0 11 1
A testUnexpectedType() 0 11 1
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\Casts;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class ArrayCastTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getDataProvider()
15
    {
16
        return array(
17
            array(array(), array()),
18
        );
19
    }
20
21
    /**
22
     * Tests (array) {expr} = {expr}
23
     *
24
     * @dataProvider getDataProvider
25
     */
26
    public function testSimpleSuccessCompile($a, $b)
27
    {
28
        $baseExpression = new Node\Expr\Cast\Array_(
29
            $this->newScalarExpr($a)
30
        );
31
        $compiledExpression = $this->compileExpression($baseExpression);
32
33
        $this->assertInstanceOfCompiledExpression($compiledExpression);
34
        $this->assertSame(CompiledExpression::ARR, $compiledExpression->getType());
35
        $this->assertSame($b, $compiledExpression->getValue());
36
    }
37
38
    public function testUnexpectedType()
39
    {
40
        $baseExpression = new Node\Expr\Cast\Array_(
41
            $this->newFakeScalarExpr()
42
        );
43
        $compiledExpression = $this->compileExpression($baseExpression);
44
45
        $this->assertInstanceOfCompiledExpression($compiledExpression);
46
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
47
        $this->assertSame(null, $compiledExpression->getValue());
48
    }
49
}
50