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

MinusTest::testIntToIntDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\Operators\Arithmetical;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class MinusTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * Data provider for Minus {int} - {int} = {int}
13
     *
14
     * @return array
15
     */
16
    public function testIntToIntDataProvider()
17
    {
18
        return array(
19
            array(-1, -1, 0),
20
            array(-1, 0, -1),
21
            array(0, -1, 1),
22
            array(-1, 2, -3),
23
            array(2, -1, 3),
24
            array(0, 0, 0),
25
            array(0, 1, -1),
26
            array(1, 0, 1),
27
            array(1, 2, -1),
28
            array(2, 1, 1),
29
            array(25, 25, 0),
30
            array(50, 25, 25),
31
            array(50, -25, 75),
32
            array(50, 50, 0),
33
            array(50, -50, 100),
34
            array(-50, -50, 0),
35
        );
36
    }
37
38
    /**
39
     * Tests {int} - {int} = {int}
40
     *
41
     * @dataProvider testIntToIntDataProvider
42
     */
43
    public function testMinusIntFromInt($a, $b, $c)
44
    {
45
        $this->assertInternalType('int', $a);
46
        $this->assertInternalType('int', $b);
47
        $this->assertInternalType('int', $c);
48
49
        $baseExpression = new Node\Expr\BinaryOp\Minus(
50
            new Node\Scalar\LNumber($a),
51
            new Node\Scalar\LNumber($b)
52
        );
53
        $compiledExpression = $this->compileExpression($baseExpression);
54
55
        $this->assertInstanceOfCompiledExpression($compiledExpression);
56
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
57
        $this->assertSame($c, $compiledExpression->getValue());
58
    }
59
60
    /**
61
     * Tests {left-expr::UNKNOWN} - {right-expr}
62
     */
63
    public function testFirstUnexpectedTypes()
64
    {
65
        $baseExpression = new Node\Expr\BinaryOp\Minus(
66
            $this->newFakeScalarExpr(),
67
            $this->newScalarExpr(1)
68
        );
69
        $compiledExpression = $this->compileExpression($baseExpression);
70
71
        $this->assertInstanceOfCompiledExpression($compiledExpression);
72
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
73
        $this->assertSame(null, $compiledExpression->getValue());
74
    }
75
76
    /**
77
     * Tests {left-expr} - {right-expr::UNKNOWN}
78
     */
79
    public function testSecondUnexpectedTypes()
80
    {
81
        $baseExpression = new Node\Expr\BinaryOp\Minus(
82
            $this->newScalarExpr(1),
83
            $this->newFakeScalarExpr()
84
        );
85
        $compiledExpression = $this->compileExpression($baseExpression);
86
87
        $this->assertInstanceOfCompiledExpression($compiledExpression);
88
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
89
        $this->assertSame(null, $compiledExpression->getValue());
90
    }
91
}
92