|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Expression\AssignOp; |
|
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 getDataProviderInteger() |
|
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 {var} &= {expr} |
|
32
|
|
|
* |
|
33
|
|
|
* @dataProvider getDataProviderInteger |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testSimpleSuccessCompileInteger($a, $b, $c) |
|
36
|
|
|
{ |
|
37
|
|
|
$baseExpression = new Node\Expr\AssignOp\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
|
|
|
/** |
|
49
|
|
|
* tests variable type unknown |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testUnexpectedTypeFirstArg() |
|
52
|
|
|
{ |
|
53
|
|
|
$baseExpression = new Node\Expr\AssignOp\BitwiseAnd( |
|
54
|
|
|
$this->newFakeScalarExpr(), |
|
55
|
|
|
$this->newScalarExpr(1) |
|
56
|
|
|
); |
|
57
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
|
60
|
|
|
$this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType()); |
|
61
|
|
|
$this->assertSame(null, $compiledExpression->getValue()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testUnexpectedTypeSecondArg() |
|
65
|
|
|
{ |
|
66
|
|
|
$baseExpression = new Node\Expr\AssignOp\BitwiseAnd( |
|
67
|
|
|
$this->newScalarExpr(1), |
|
68
|
|
|
$this->newFakeScalarExpr() |
|
69
|
|
|
); |
|
70
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
|
73
|
|
|
$this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType()); |
|
74
|
|
|
$this->assertSame(null, $compiledExpression->getValue()); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|