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

LogicalXorTest::getDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 18
nc 1
nop 0
dl 0
loc 21
rs 9.3142
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 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