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

BooleanOrTest::getDataProvider()   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\Operators\Logical;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class BooleanOrTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getDataProvider()
15
    {
16
        return array(
17
            array(true, true, true),
18
            array(true, false, true),
19
            array(false, true, true),
20
            array(false, false, false),
21
            array(null, false, false),
22
            array(false, null, false),
23
            array(null, null, false),
24
            array(true, null, true),
25
            array(null, true, true),
26
        );
27
    }
28
29
    /**
30
     * Tests {expr} || {expr} = {expr}
31
     *
32
     * @dataProvider getDataProvider
33
     */
34
    public function testSimpleSuccessCompile($a, $b, $c)
35
    {
36
        $baseExpression = new Node\Expr\BinaryOp\BooleanOr(
37
            $this->newScalarExpr($a),
38
            $this->newScalarExpr($b)
39
        );
40
        $compiledExpression = $this->compileExpression($baseExpression);
41
42
        $this->assertInstanceOfCompiledExpression($compiledExpression);
43
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
44
        $this->assertSame($c, $compiledExpression->getValue());
45
    }
46
47
    public function testUnexpectedTypes()
48
    {
49
        $baseExpression = new Node\Expr\BinaryOp\BooleanOr(
50
            $this->newScalarExpr(1),
51
            $this->newFakeScalarExpr()
52
        );
53
        $compiledExpression = $this->compileExpression($baseExpression);
54
55
        $this->assertInstanceOfCompiledExpression($compiledExpression);
56
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
57
        $this->assertSame(null, $compiledExpression->getValue());
58
    }
59
}
60