|
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 MulTest extends AbstractBinaryOp |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param $a |
|
14
|
|
|
* @param $b |
|
15
|
|
|
* @return mixed |
|
16
|
|
|
*/ |
|
17
|
|
|
protected function process($a, $b) |
|
18
|
|
|
{ |
|
19
|
|
|
return $a * $b; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function getSupportedTypes() |
|
26
|
|
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
CompiledExpression::INTEGER, |
|
29
|
|
|
CompiledExpression::DOUBLE, |
|
30
|
|
|
CompiledExpression::BOOLEAN, |
|
31
|
|
|
]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Data provider for {var} *= {expr} with result type = double |
|
36
|
|
|
* |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
|
|
public function mulResultDoubleDataProvider() |
|
40
|
|
|
{ |
|
41
|
|
|
return [ |
|
42
|
|
|
[2, 1.5, 3.0], |
|
43
|
|
|
[1.5, 1.5, 2.25], |
|
44
|
|
|
[true, 1.5, 1.5], |
|
45
|
|
|
[false, 1.5, 0.0], |
|
46
|
|
|
[1.5, false, 0.0], |
|
47
|
|
|
[1.5, true, 1.5], |
|
48
|
|
|
[-1.5, true, -1.5], |
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Tests {var} *= {expr} with result type = double |
|
54
|
|
|
* |
|
55
|
|
|
* @dataProvider mulResultDoubleDataProvider |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testMulResultDouble($a, $b, $c) |
|
58
|
|
|
{ |
|
59
|
|
|
|
|
60
|
|
|
$baseExpression = new Node\Expr\AssignOp\Mul( |
|
61
|
|
|
$this->newScalarExpr($a), |
|
62
|
|
|
$this->newScalarExpr($b) |
|
63
|
|
|
); |
|
64
|
|
|
$compiledExpression = $this->compileExpression($baseExpression); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
|
67
|
|
|
$this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType()); |
|
68
|
|
|
$this->assertSame($c, $compiledExpression->getValue()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param Node\Scalar $a |
|
73
|
|
|
* @param Node\Scalar $b |
|
74
|
|
|
* @return Node\Expr\AssignOp\Mul |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function buildExpression($a, $b) |
|
77
|
|
|
{ |
|
78
|
|
|
return new Node\Expr\AssignOp\Mul($a, $b); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|