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

BooleanNotTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 13 1
A testSimpleSuccessCompile() 0 11 1
A testUnexpectedType() 0 11 1
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