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

LogicalXorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 21 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 LogicalXorTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getDataProvider()
15
    {
16
        return array(
17
            array(true, true, false),
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, false),
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} xor {expr} = {expr}
38
     *
39
     * @dataProvider getDataProvider
40
     */
41
    public function testSimpleSuccessCompile($a, $b, $c)
42
    {
43
        $baseExpression = new Node\Expr\BinaryOp\LogicalXor(
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\LogicalXor(
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