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

LogicalAndTest::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 LogicalAndTest 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(false, true, false),
19
            array(true, false, false),
20
            array(false, false, false),
21
            array(null, null, false),
22
            array(true, null, false),
23
            array(null, true, false),
24
            array(1, true, true),
25
            array(1.4, true, true),
26
            array(1, false, false),
27
            array(-1, true, true),
28
            array("a", true, true),
29
            array(array(), array(), false),
30
            array(array(), "a", false),
31
        );
32
    }
33
34
    /**
35
     * Tests {expr} and {expr} = {expr}
36
     *
37
     * @dataProvider getDataProvider
38
     */
39
    public function testSimpleSuccessCompile($a, $b, $c)
40
    {
41
        $baseExpression = new Node\Expr\BinaryOp\LogicalAnd(
42
            $this->newScalarExpr($a),
43
            $this->newScalarExpr($b)
44
        );
45
        $compiledExpression = $this->compileExpression($baseExpression);
46
47
        $this->assertInstanceOfCompiledExpression($compiledExpression);
48
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
49
        $this->assertSame($c, $compiledExpression->getValue());
50
    }
51
52
    public function testUnexpectedTypes()
53
    {
54
        $baseExpression = new Node\Expr\BinaryOp\LogicalAnd(
55
            $this->newScalarExpr(1),
56
            $this->newFakeScalarExpr()
57
        );
58
        $compiledExpression = $this->compileExpression($baseExpression);
59
60
        $this->assertInstanceOfCompiledExpression($compiledExpression);
61
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
62
        $this->assertSame(null, $compiledExpression->getValue());
63
    }
64
}
65