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

IntCastTest::buildExpression()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nop 1
rs 10
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
use Tests\PHPSA\Compiler\Expression\AbstractUnaryOp;
9
10
class IntCastTest extends AbstractUnaryOp
11
{
12
    /**
13
     * @return array
14
     */
15
    public function getDataProvider()
16
    {
17
        return [
18
            [true, 1],
19
            [0, 0],
20
            [-1, -1],
21
            [1.4, 1],
22
            ["a", 0],
23
            [[], 0],
24
        ];
25
    }
26
27
    /**
28
     * Tests (int) {expr} = {expr}
29
     *
30
     * @dataProvider getDataProvider
31
     */
32
    public function testIntCastCompile($a, $b)
33
    {
34
        $baseExpression = new Node\Expr\Cast\Int_(
35
            $this->newScalarExpr($a)
36
        );
37
        $compiledExpression = $this->compileExpression($baseExpression);
38
39
        $this->assertInstanceOfCompiledExpression($compiledExpression);
40
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
41
        $this->assertSame($b, $compiledExpression->getValue());
42
    }
43
44
    /**
45
     * @param Node\Scalar $a
46
     * @return Node\Expr\Cast\Int_
47
     */
48
    protected function buildExpression($a)
49
    {
50
        return new Node\Expr\Cast\Int_($a);
51
    }
52
}
53