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

BitwiseOrTest::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 BitwiseOrTest extends AbstractBinaryOp
11
{
12
    /**
13
     * @return array
14
     */
15
    public function getDataProvider()
16
    {
17
        return [
18
            [0, 5, 5],
19
            [1, 5, 5],
20
            [4, 5, 5],
21
            [-1, 5, -1],
22
            [1.4, 5, 5],
23
            [-19.7, 1, -19],
24
            [true, true, 1],
25
            [false, true, 1],
26
            [true, false, 1],
27
            [false, false, 0],
28
        ];
29
    }
30
31
    /**
32
     * Tests {var} |= {expr}
33
     *
34
     * @dataProvider getDataProvider
35
     */
36
    public function testSimpleSuccessCompile($a, $b, $c)
37
    {
38
        $baseExpression = new Node\Expr\AssignOp\BitwiseOr(
39
            $this->newScalarExpr($a),
40
            $this->newScalarExpr($b)
41
        );
42
        $compiledExpression = $this->compileExpression($baseExpression);
43
44
        $this->assertInstanceOfCompiledExpression($compiledExpression);
45
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
46
        $this->assertSame($c, $compiledExpression->getValue());
47
    }
48
49
    /**
50
     * @param Node\Scalar $a
51
     * @param Node\Scalar $b
52
     * @return Node\Expr\AssignOp\BitwiseOr
53
     */
54
    protected function buildExpression($a, $b)
55
    {
56
        return new Node\Expr\AssignOp\BitwiseOr($a, $b);
57
    }
58
}
59