Completed
Pull Request — master (#304)
by Enrico
03:09
created

MinusTest::minusResultIntDataProvider()   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
use Tests\PHPSA\Compiler\Expression\AbstractBinaryOp;
9
10
class MinusTest extends AbstractBinaryOp
11
{
12
    /**
13
     * Data provider for {var} -= {expr} with result type = int
14
     *
15
     * @return array
16
     */
17
    public function minusResultIntDataProvider()
18
    {
19
        return [
20
            [2, 2, 0],
21
            [true, 2, -1],
22
            [3, true, 2],
23
            [true, true, 0],
24
            [2, 0, 2],
25
            [-1, 1, -2],
26
            [false, 3, -3],
27
            [2, false, 2],
28
            [false, false, 0],
29
            [0, 0, 0],
30
            [true, false, 1],
31
        ];
32
    }
33
34
    /**
35
     * Tests {var} -= {expr} with result type = int
36
     *
37
     * @dataProvider minusResultIntDataProvider
38
     */
39
    public function testMinusResultInt($a, $b, $c)
40
    {
41
42
        $baseExpression = new Node\Expr\AssignOp\Minus(
43
            $this->newScalarExpr($a),
44
            $this->newScalarExpr($b)
45
        );
46
        $compiledExpression = $this->compileExpression($baseExpression);
47
48
        $this->assertInstanceOfCompiledExpression($compiledExpression);
49
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
50
        $this->assertSame($c, $compiledExpression->getValue());
51
    }
52
53
    /**
54
     * Data provider for {var} -= {expr} with result type = double
55
     *
56
     * @return array
57
     */
58
    public function minusResultDoubleDataProvider()
59
    {
60
        return [
61
            [2, 1.5, 0.5],
62
            [1.5, 2, -0.5],
63
            [true, 1.5, -0.5],
64
            [false, 1.5, -1.5],
65
            [1.5, false, 1.5],
66
            [1.5, true, 0.5],
67
            [-1.5, 1, -2.5],
68
        ];
69
    }
70
71
    /**
72
     * Tests {var} -= {expr} with result type = double
73
     *
74
     * @dataProvider minusResultDoubleDataProvider
75
     */
76
    public function testMinusResultDouble($a, $b, $c)
77
    {
78
79
        $baseExpression = new Node\Expr\AssignOp\Minus(
80
            $this->newScalarExpr($a),
81
            $this->newScalarExpr($b)
82
        );
83
        $compiledExpression = $this->compileExpression($baseExpression);
84
85
        $this->assertInstanceOfCompiledExpression($compiledExpression);
86
        $this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType());
87
        $this->assertSame($c, $compiledExpression->getValue());
88
    }
89
90
    /**
91
     * @param Node\Scalar $a
92
     * @param Node\Scalar $b
93
     * @return Node\Expr\AssignOp\Minus
94
     */
95
    protected function buildExpression($a, $b)
96
    {
97
        return new Node\Expr\AssignOp\Minus($a, $b);
98
    }
99
}
100