Completed
Push — master ( 558809...774145 )
by Дмитрий
03:36
created

BitwiseAndTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 65
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 15 1
A testSimpleSuccessCompile() 0 12 1
A testUnexpectedTypeFirstArg() 0 12 1
A testUnexpectedTypeSecondArg() 0 12 1
1
<?php
2
3
namespace Tests\PHPSA\Expression\Operators\Bitwise;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class BitwiseAndTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getDataProvider()
15
    {
16
        return array(
17
            array(0, 5, 0),
18
            array(1, 5, 1),
19
            array(4, 5, 4),
20
            array(-1, 5, 5),
21
            array(1.4, 5, 1),
22
            array(-19.7, 1, 1),
23
            array(true, true, 1),
24
            array(false, true, 0),
25
            array(true, false, 0),
26
            array(false, false, 0),
27
        );
28
    }
29
30
    /**
31
     * Tests {expr} & {expr} = {expr}
32
     *
33
     * @dataProvider getDataProvider
34
     */
35
    public function testSimpleSuccessCompile($a, $b, $c)
36
    {
37
        $baseExpression = new Node\Expr\BinaryOp\BitwiseAnd(
38
            $this->newScalarExpr($a),
39
            $this->newScalarExpr($b)
40
        );
41
        $compiledExpression = $this->compileExpression($baseExpression);
42
43
        $this->assertInstanceOfCompiledExpression($compiledExpression);
44
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
45
        $this->assertSame($c, $compiledExpression->getValue());
46
    }
47
48
    public function testUnexpectedTypeFirstArg()
49
    {
50
        $baseExpression = new Node\Expr\BinaryOp\BitwiseAnd(
51
            $this->newFakeScalarExpr(),
52
            $this->newScalarExpr(1)
53
        );
54
        $compiledExpression = $this->compileExpression($baseExpression);
55
56
        $this->assertInstanceOfCompiledExpression($compiledExpression);
57
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
58
        $this->assertSame(null, $compiledExpression->getValue());
59
    }
60
61
    public function testUnexpectedTypeSecondArg()
62
    {
63
        $baseExpression = new Node\Expr\BinaryOp\BitwiseAnd(
64
            $this->newScalarExpr(1),
65
            $this->newFakeScalarExpr()
66
        );
67
        $compiledExpression = $this->compileExpression($baseExpression);
68
69
        $this->assertInstanceOfCompiledExpression($compiledExpression);
70
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
71
        $this->assertSame(null, $compiledExpression->getValue());
72
    }
73
}
74