Completed
Pull Request — master (#124)
by Enrico
03:49
created

NotEqualTest::testSecondUnexpectedTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\BinaryOp;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class NotEqualTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function providerForStaticEqualsTrue()
15
    {
16
        return array(
17
            array(-1, -2),
18
            //boolean true
19
            array(true, false),
20
            array(true, 0),
21
            array(0, true),
22
            // boolean false
23
            array(false, true),
24
            array(false, 1),
25
            array(1, false)
26
            //@todo arrays....
27
        );
28
    }
29
30
    /**
31
     * Tests {left-expr} != {right-expr}
32
     *
33
     * @param int $a
34
     * @param int $b
35
     *
36
     * @dataProvider providerForStaticEqualsTrue
37
     */
38
    public function testStaticEqualsTrue($a, $b)
39
    {
40
        $baseExpression = new Node\Expr\BinaryOp\NotEqual(
41
            $this->newScalarExpr($a),
42
            $this->newScalarExpr($b)
43
        );
44
        $compiledExpression = $this->compileExpression($baseExpression, $this->getContext());
45
46
        $this->assertInstanceOfCompiledExpression($compiledExpression);
47
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
48
        $this->assertSame(true, $compiledExpression->getValue());
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function providerForStaticEqualsFalse()
55
    {
56
        return array(
57
            array(-1, -1),
58
            array(1, 1),
59
            array(1, 1),
60
            array(0, 0),
61
            array(true, 1),
62
            array(1, true),
63
            array(false, 0),
64
            array(false, false)
65
            //@todo arrays....
66
        );
67
    }
68
69
    /**
70
     * Tests {left-expr} == {right-expr} but for false
71
     *
72
     * @param int $a
73
     * @param int $b
74
     *
75
     * @dataProvider providerForStaticEqualsFalse
76
     */
77
    public function testStaticEqualsFalse($a, $b)
78
    {
79
        $baseExpression = new Node\Expr\BinaryOp\NotEqual(
80
            $this->newScalarExpr($a),
81
            $this->newScalarExpr($b)
82
        );
83
        $compiledExpression = $this->compileExpression($baseExpression, $this->getContext());
84
85
        $this->assertInstanceOfCompiledExpression($compiledExpression);
86
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
87
        $this->assertSame(false, $compiledExpression->getValue());
88
    }
89
90
    /**
91
     * Tests {left-expr::UNKNOWN} == {right-expr}
92
     */
93
    public function testFirstUnexpectedTypes()
94
    {
95
        $baseExpression = new Node\Expr\BinaryOp\NotEqual(
96
            $this->newFakeScalarExpr(),
97
            $this->newScalarExpr(1)
98
        );
99
        $compiledExpression = $this->compileExpression($baseExpression, $this->getContext());
100
101
        $this->assertInstanceOfCompiledExpression($compiledExpression);
102
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
103
        $this->assertSame(null, $compiledExpression->getValue());
104
    }
105
106
    /**
107
     * Tests {left-expr} == {right-expr::UNKNOWN}
108
     */
109
    public function testSecondUnexpectedTypes()
110
    {
111
        $baseExpression = new Node\Expr\BinaryOp\NotEqual(
112
            $this->newScalarExpr(1),
113
            $this->newFakeScalarExpr()
114
        );
115
        $compiledExpression = $this->compileExpression($baseExpression, $this->getContext());
116
117
        $this->assertInstanceOfCompiledExpression($compiledExpression);
118
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
119
        $this->assertSame(null, $compiledExpression->getValue());
120
    }
121
}
122