Completed
Pull Request — master (#120)
by Enrico
02:58
created

LogicalOrTest::testSimpleSuccessCompile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 3
dl 0
loc 12
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Expression\Operators\Logical;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class LogicalOrTest 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
            array(1, true, true),
27
            array(1.4, false, true),
28
            array(1, false, true),
29
            array(-1, false, true),
30
            array("a", false, true),
31
            array(array(), array(), false),
32
            array(array(), "a", true),
33
        );
34
    }
35
36
    /**
37
     * Tests {expr} or {expr} = {expr}
38
     *
39
     * @dataProvider getDataProvider
40
     */
41
    public function testSimpleSuccessCompile($a, $b, $c)
42
    {
43
        $baseExpression = new Node\Expr\BinaryOp\LogicalOr(
44
            $this->newScalarExpr($a),
45
            $this->newScalarExpr($b)
46
        );
47
        $compiledExpression = $this->compileExpression($baseExpression);
48
49
        $this->assertInstanceOfCompiledExpression($compiledExpression);
50
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
51
        $this->assertSame($c, $compiledExpression->getValue());
52
    }
53
54
    public function testUnexpectedTypes()
55
    {
56
        $baseExpression = new Node\Expr\BinaryOp\LogicalOr(
57
            $this->newScalarExpr(1),
58
            $this->newFakeScalarExpr()
59
        );
60
        $compiledExpression = $this->compileExpression($baseExpression);
61
62
        $this->assertInstanceOfCompiledExpression($compiledExpression);
63
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
64
        $this->assertSame(null, $compiledExpression->getValue());
65
    }
66
}
67