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

ModTest::modDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 14
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 ModTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * Data provider for {var} %= {expr} with result type = int
13
     *
14
     * @return array
15
     */
16
    public function modDataProvider()
17
    {
18
        return array(
19
            array(2, 2, 0),
20
            array(true, 2, 1),
21
            array(3, true, 0),
22
            array(true, true, 0),
23
            array(-1, 1, 0),
24
            array(false, 3, 0),
25
            array(false, true, 0),
26
            array(0, 1, 0),
27
            array(1, -1, 0),
28
        );
29
    }
30
31
    /**
32
     * Tests {var} %= {expr} with result type = int
33
     *
34
     * @dataProvider modDataProvider
35
     */
36
    public function testModResultInt($a, $b, $c)
37
    {
38
39
        $baseExpression = new Node\Expr\AssignOp\Mod(
40
            $this->newScalarExpr($a),
41
            $this->newScalarExpr($b)
42
        );
43
        $compiledExpression = $this->compileExpression($baseExpression);
44
45
        $this->assertInstanceOfCompiledExpression($compiledExpression);
46
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
47
        $this->assertSame($c, $compiledExpression->getValue());
48
    }
49
50
    /**
51
     * Tests {var-type::UNKNOWN} %= {right-expr}
52
     */
53
    public function testFirstUnexpectedType()
54
    {
55
        $baseExpression = new Node\Expr\AssignOp\Mod(
56
            $this->newFakeScalarExpr(),
57
            $this->newScalarExpr(1)
58
        );
59
        $compiledExpression = $this->compileExpression($baseExpression);
60
61
        $this->assertInstanceOfCompiledExpression($compiledExpression);
62
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
63
        $this->assertSame(null, $compiledExpression->getValue());
64
    }
65
66
    /**
67
     * Tests {var} %= {right-expr::UNKNOWN}
68
     */
69
    public function testSecondUnexpectedType()
70
    {
71
        $baseExpression = new Node\Expr\AssignOp\Mod(
72
            $this->newScalarExpr(1),
73
            $this->newFakeScalarExpr()
74
        );
75
        $compiledExpression = $this->compileExpression($baseExpression);
76
77
        $this->assertInstanceOfCompiledExpression($compiledExpression);
78
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
79
        $this->assertSame(null, $compiledExpression->getValue());
80
    }
81
}
82