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

BooleanAndTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 9 1
A testSimpleSuccessCompile() 0 12 1
A testUnexpectedTypes() 0 12 1
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 BooleanAndTest 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
        );
22
    }
23
24
    /**
25
     * Tests {expr} && {expr} = {expr}
26
     *
27
     * @dataProvider getDataProvider
28
     */
29
    public function testSimpleSuccessCompile($a, $b, $c)
30
    {
31
        $baseExpression = new Node\Expr\BinaryOp\BooleanAnd(
32
            $this->newScalarExpr($a),
33
            $this->newScalarExpr($b)
34
        );
35
        $compiledExpression = $this->compileExpression($baseExpression);
36
37
        $this->assertInstanceOfCompiledExpression($compiledExpression);
38
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
39
        $this->assertSame($c, $compiledExpression->getValue());
40
    }
41
42
    public function testUnexpectedTypes()
43
    {
44
        $baseExpression = new Node\Expr\BinaryOp\BooleanAnd(
45
            $this->newScalarExpr(1),
46
            $this->newFakeScalarExpr()
47
        );
48
        $compiledExpression = $this->compileExpression($baseExpression);
49
50
        $this->assertInstanceOfCompiledExpression($compiledExpression);
51
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
52
        $this->assertSame(null, $compiledExpression->getValue());
53
    }
54
}
55