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

BooleanNotTest::testSimpleSuccessCompile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
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
/**
10
 * Class BooleanNotTest
11
 * @package Tests\PHPSA\Expression\Operators\Logical
12
 */
13
class BooleanNotTest extends \Tests\PHPSA\TestCase
14
{
15
    /**
16
     * @return array
17
     */
18
    public function getDataProvider()
19
    {
20
        return array(
21
            array(true, false),
22
            array(false, true),
23
            array(1, false),
24
            array(-1, false),
25
            array(1.4, false),
26
            array(null, true),
27
            array("a", false),
28
            array(array(), true),
29
        );
30
    }
31
32
    /**
33
     * Tests !{expr}
34
     *
35
     * @see \PHPSA\Compiler\Expression\Operators\Logical\BooleanNot
36
     * @dataProvider getDataProvider
37
     */
38
    public function testSimpleSuccessCompile($a, $b)
39
    {
40
        $baseExpression = new Node\Expr\BooleanNot(
41
            $this->newScalarExpr($a)
42
        );
43
        $compiledExpression = $this->compileExpression($baseExpression);
44
45
        $this->assertInstanceOfCompiledExpression($compiledExpression);
46
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
47
        $this->assertSame($b, $compiledExpression->getValue());
48
    }
49
50
    public function testUnexpectedType()
51
    {
52
        $baseExpression = new Node\Expr\BooleanNot(
53
            $this->newFakeScalarExpr()
54
        );
55
        $compiledExpression = $this->compileExpression($baseExpression);
56
57
        $this->assertInstanceOfCompiledExpression($compiledExpression);
58
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
59
        $this->assertSame(null, $compiledExpression->getValue());
60
    }
61
}
62