Completed
Push — master ( fba3d8...90421b )
by Дмитрий
04:23 queued 23s
created

LogicalAndTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 19 1
A testSimpleSuccessCompile() 0 12 1
A testUnexpectedTypes() 0 12 1
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