Completed
Pull Request — master (#124)
by Enrico
04:01 queued 01:12
created

BooleanNotTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 9 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
        );
26
    }
27
28
    /**
29
     * Tests !{expr}
30
     *
31
     * @see \PHPSA\Compiler\Expression\Operators\Logical\BooleanNot
32
     * @dataProvider getDataProvider
33
     */
34
    public function testSimpleSuccessCompile($a, $b)
35
    {
36
        $baseExpression = new Node\Expr\BooleanNot(
37
            $this->newScalarExpr($a)
38
        );
39
        $compiledExpression = $this->compileExpression($baseExpression);
40
41
        $this->assertInstanceOfCompiledExpression($compiledExpression);
42
        $this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType());
43
        $this->assertSame($b, $compiledExpression->getValue());
44
    }
45
46
    public function testUnexpectedType()
47
    {
48
        $baseExpression = new Node\Expr\BooleanNot(
49
            $this->newFakeScalarExpr()
50
        );
51
        $compiledExpression = $this->compileExpression($baseExpression);
52
53
        $this->assertInstanceOfCompiledExpression($compiledExpression);
54
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
55
        $this->assertSame(null, $compiledExpression->getValue());
56
    }
57
}
58