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

ModTest::buildExpression()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nop 2
rs 10
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 ModTest extends AbstractBinaryOp
11
{
12
    /**
13
     * Data provider for {var} %= {expr} with result type = int
14
     *
15
     * @return array
16
     */
17
    public function modDataProvider()
18
    {
19
        return [
20
            [2, 2, 0],
21
            [true, 2, 1],
22
            [3, true, 0],
23
            [true, true, 0],
24
            [-1, 1, 0],
25
            [false, 3, 0],
26
            [false, true, 0],
27
            [0, 1, 0],
28
            [1, -1, 0],
29
        ];
30
    }
31
32
    /**
33
     * Tests {var} %= {expr} with result type = int
34
     *
35
     * @dataProvider modDataProvider
36
     */
37
    public function testModResultInt($a, $b, $c)
38
    {
39
40
        $baseExpression = new Node\Expr\AssignOp\Mod(
41
            $this->newScalarExpr($a),
42
            $this->newScalarExpr($b)
43
        );
44
        $compiledExpression = $this->compileExpression($baseExpression);
45
46
        $this->assertInstanceOfCompiledExpression($compiledExpression);
47
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
48
        $this->assertSame($c, $compiledExpression->getValue());
49
    }
50
51
    /**
52
     * @param Node\Scalar $a
53
     * @param Node\Scalar $b
54
     * @return Node\Expr\AssignOp\Mod
55
     */
56
    protected function buildExpression($a, $b)
57
    {
58
        return new Node\Expr\AssignOp\Mod($a, $b);
59
    }
60
}
61