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

DoubleCastTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 11 1
A testDoubleCastCompile() 0 11 1
A buildExpression() 0 4 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
use Tests\PHPSA\Compiler\Expression\AbstractUnaryOp;
9
10
class DoubleCastTest extends AbstractUnaryOp
11
{
12
    /**
13
     * @return array
14
     */
15
    public function getDataProvider()
16
    {
17
        return [
18
            [true, 1.0],
19
            [0, 0.0],
20
            [-1, -1.0],
21
            [1.4, 1.4],
22
            ["a", 0.0],
23
            [[], 0.0],
24
        ];
25
    }
26
27
    /**
28
     * Tests (double) {expr} = {expr}
29
     *
30
     * @dataProvider getDataProvider
31
     */
32
    public function testDoubleCastCompile($a, $b)
33
    {
34
        $baseExpression = new Node\Expr\Cast\Double(
35
            $this->newScalarExpr($a)
36
        );
37
        $compiledExpression = $this->compileExpression($baseExpression);
38
39
        $this->assertInstanceOfCompiledExpression($compiledExpression);
40
        $this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType());
41
        $this->assertSame($b, $compiledExpression->getValue());
42
    }
43
44
    /**
45
     * @param Node\Scalar $a
46
     * @return Node\Expr\Cast\Double
47
     */
48
    protected function buildExpression($a)
49
    {
50
        return new Node\Expr\Cast\Double($a);
51
    }
52
}
53