1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Compiler\Expression\AssignOp; |
4
|
|
|
|
5
|
|
|
use PhpParser\Node; |
6
|
|
|
use PHPSA\CompiledExpression; |
7
|
|
|
use PHPSA\Compiler\Expression; |
8
|
|
|
use Tests\PHPSA\Compiler\Expression\AbstractBinaryOp; |
9
|
|
|
|
10
|
|
|
class DivTest extends AbstractBinaryOp |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Data provider for {var} /= {expr} with result type = int |
14
|
|
|
* |
15
|
|
|
* @return array |
16
|
|
|
*/ |
17
|
|
|
public function divResultIntDataProvider() |
18
|
|
|
{ |
19
|
|
|
return [ |
20
|
|
|
[2, 2, 1], |
21
|
|
|
[true, 1, 1], |
22
|
|
|
[3, true, 3], |
23
|
|
|
[true, true, 1], |
24
|
|
|
[2, 1, 2], |
25
|
|
|
[-1, 1, -1], |
26
|
|
|
[false, -3, 0], |
27
|
|
|
[false, 1, 0], |
28
|
|
|
[0, 1, 0], |
29
|
|
|
[false, true, 0], |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Tests {var} /= {expr} with result type = int |
35
|
|
|
* |
36
|
|
|
* @dataProvider divResultIntDataProvider |
37
|
|
|
*/ |
38
|
|
|
public function testDivResultInt($a, $b, $c) |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
$baseExpression = new Node\Expr\AssignOp\Div( |
42
|
|
|
$this->newScalarExpr($a), |
43
|
|
|
$this->newScalarExpr($b) |
44
|
|
|
); |
45
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
46
|
|
|
|
47
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
48
|
|
|
$this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType()); |
49
|
|
|
$this->assertSame($c, $compiledExpression->getValue()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Data provider for {var} /= {expr} with result type = double |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function divResultDoubleDataProvider() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
[2, 0.5, 4.0], |
61
|
|
|
[1.5, 0.5, 3.0], |
62
|
|
|
[true, 2, 0.5], |
63
|
|
|
[false, -5.5, 0.0], |
64
|
|
|
[1.5, true, 1.5], |
65
|
|
|
[-1.5, 1, -1.5], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Tests {var} /= {expr} with result type = double |
71
|
|
|
* |
72
|
|
|
* @dataProvider divResultDoubleDataProvider |
73
|
|
|
*/ |
74
|
|
|
public function testDivResultDouble($a, $b, $c) |
75
|
|
|
{ |
76
|
|
|
|
77
|
|
|
$baseExpression = new Node\Expr\AssignOp\Div( |
78
|
|
|
$this->newScalarExpr($a), |
79
|
|
|
$this->newScalarExpr($b) |
80
|
|
|
); |
81
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
82
|
|
|
|
83
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
84
|
|
|
$this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType()); |
85
|
|
|
$this->assertSame($c, $compiledExpression->getValue()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param Node\Scalar $a |
90
|
|
|
* @param Node\Scalar $b |
91
|
|
|
* @return Node\Expr\AssignOp\Div |
92
|
|
|
*/ |
93
|
|
|
protected function buildExpression($a, $b) |
94
|
|
|
{ |
95
|
|
|
return new Node\Expr\AssignOp\Div($a, $b); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|