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

DoubleCastTest::testUnexpectedType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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 DoubleCastTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getDataProvider()
15
    {
16
        return array(
17
            array(true, 1.0),
18
            array(0, 0.0),
19
            array(-1, -1.0),
20
            array(1.4, 1.4),
21
            array("a", 0.0),
22
            array(array(), 0.0),
23
        );
24
    }
25
26
    /**
27
     * Tests (double) {expr} = {expr}
28
     *
29
     * @dataProvider getDataProvider
30
     */
31
    public function testSimpleSuccessCompile($a, $b)
32
    {
33
        $baseExpression = new Node\Expr\Cast\Double(
34
            $this->newScalarExpr($a)
35
        );
36
        $compiledExpression = $this->compileExpression($baseExpression);
37
38
        $this->assertInstanceOfCompiledExpression($compiledExpression);
39
        $this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType());
40
        $this->assertSame($b, $compiledExpression->getValue());
41
    }
42
43
    public function testUnexpectedType()
44
    {
45
        $baseExpression = new Node\Expr\Cast\Double(
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