Completed
Push — master ( 5f2691...53c2bd )
by Enrico
03:49
created

IntCastTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 11 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 IntCastTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getDataProvider()
15
    {
16
        return array(
17
            array(true, 1),
18
            array(0, 0),
19
            array(-1, -1),
20
            array(1.4, 1),
21
            array("a", 0),
22
            array(array(), 0),
23
        );
24
    }
25
26
    /**
27
     * Tests (int) {expr} = {expr}
28
     *
29
     * @dataProvider getDataProvider
30
     */
31
    public function testSimpleSuccessCompile($a, $b)
32
    {
33
        $baseExpression = new Node\Expr\Cast\Int_(
34
            $this->newScalarExpr($a)
35
        );
36
        $compiledExpression = $this->compileExpression($baseExpression);
37
38
        $this->assertInstanceOfCompiledExpression($compiledExpression);
39
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
40
        $this->assertSame($b, $compiledExpression->getValue());
41
    }
42
43
    public function testUnexpectedType()
44
    {
45
        $baseExpression = new Node\Expr\Cast\Int_(
46
            $this->newFakeScalarExpr()
47
        );
48
        $compiledExpression = $this->compileExpression($baseExpression);
49
50
        $this->assertInstanceOfCompiledExpression($compiledExpression);
51
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
52
        $this->assertSame(null, $compiledExpression->getValue());
53
    }
54
}
55