Completed
Pull Request — master (#178)
by Cláudio
03:52 queued 21s
created

MulTest::mulResultIntDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\AssignOp;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class MulTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * Data provider for {var} *= {expr} with result type = int
13
     *
14
     * @return array
15
     */
16
    public function mulResultIntDataProvider()
17
    {
18
        return array(
19
            array(2, 2, 4),
20
            array(true, 2, 2),
21
            array(3, true, 3),
22
            array(true, true, 1),
23
            array(2, 0, 0),
24
            array(false, 3, 0),
25
            array(2, false, 0),
26
            array(false, false, 0),
27
            array(0, 0, 0),
28
            array(true, false, 0),
29
            array(-1, 2, -2),
30
        );
31
    }
32
33
    /**
34
     * Tests {var} *= {expr} with result type = int
35
     *
36
     * @dataProvider mulResultIntDataProvider
37
     */
38
    public function testMulResultInt($a, $b, $c)
39
    {
40
41
        $baseExpression = new Node\Expr\AssignOp\Mul(
42
            $this->newScalarExpr($a),
43
            $this->newScalarExpr($b)
44
        );
45
        $compiledExpression = $this->compileExpression($baseExpression);
46
47
        $this->assertInstanceOfCompiledExpression($compiledExpression);
48
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
49
        $this->assertSame($c, $compiledExpression->getValue());
50
    }
51
52
    /**
53
     * Data provider for {var} *= {expr} with result type = double
54
     *
55
     * @return array
56
     */
57
    public function mulResultDoubleDataProvider()
58
    {
59
        return array(
60
            array(2, 1.5, 3.0),
61
            array(1.5, 1.5, 2.25),
62
            array(true, 1.5, 1.5),
63
            array(false, 1.5, 0.0),
64
            array(1.5, false, 0.0),
65
            array(1.5, true, 1.5),
66
            array(-1.5, true, -1.5),
67
        );
68
    }
69
70
    /**
71
     * Tests {var} *= {expr} with result type = double
72
     *
73
     * @dataProvider mulResultDoubleDataProvider
74
     */
75
    public function testMulResultDouble($a, $b, $c)
76
    {
77
78
        $baseExpression = new Node\Expr\AssignOp\Mul(
79
            $this->newScalarExpr($a),
80
            $this->newScalarExpr($b)
81
        );
82
        $compiledExpression = $this->compileExpression($baseExpression);
83
84
        $this->assertInstanceOfCompiledExpression($compiledExpression);
85
        $this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType());
86
        $this->assertSame($c, $compiledExpression->getValue());
87
    }
88
89
    /**
90
     * Tests {var-type::UNKNOWN} *= {right-expr}
91
     */
92
    public function testFirstUnexpectedType()
93
    {
94
        $baseExpression = new Node\Expr\AssignOp\Mul(
95
            $this->newFakeScalarExpr(),
96
            $this->newScalarExpr(1)
97
        );
98
        $compiledExpression = $this->compileExpression($baseExpression);
99
100
        $this->assertInstanceOfCompiledExpression($compiledExpression);
101
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
102
        $this->assertSame(null, $compiledExpression->getValue());
103
    }
104
105
    /**
106
     * Tests {var} *= {right-expr::UNKNOWN}
107
     */
108
    public function testSecondUnexpectedType()
109
    {
110
        $baseExpression = new Node\Expr\AssignOp\Mul(
111
            $this->newScalarExpr(1),
112
            $this->newFakeScalarExpr()
113
        );
114
        $compiledExpression = $this->compileExpression($baseExpression);
115
116
        $this->assertInstanceOfCompiledExpression($compiledExpression);
117
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
118
        $this->assertSame(null, $compiledExpression->getValue());
119
    }
120
}
121