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

BitwiseAndTest::getDataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 1
b 0
f 0
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