1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\PHPSA\Compiler\Expression\BinaryOp; |
4
|
|
|
|
5
|
|
|
use PhpParser\Node; |
6
|
|
|
use PHPSA\CompiledExpression; |
7
|
|
|
use PHPSA\Compiler\Expression; |
8
|
|
|
use Tests\PHPSA\Compiler\Expression\AbstractBinaryOp; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class NotIndenticalTest |
13
|
|
|
* @package Tests\PHPSA\Expression\BinaryOp |
14
|
|
|
*/ |
15
|
|
|
class NotIndenticalTest extends AbstractBinaryOp |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @return array |
19
|
|
|
*/ |
20
|
|
|
public function providerForStaticIntToIntCases() |
21
|
|
|
{ |
22
|
|
|
return [ |
23
|
|
|
[-1, -2], |
24
|
|
|
[-1, 0], |
25
|
|
|
[-5, -4], |
26
|
|
|
[-150, -151], |
27
|
|
|
[150, 151], |
28
|
|
|
[151, 150], |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Tests (int) {left-expr} !=== (int) {right-expr} |
34
|
|
|
* |
35
|
|
|
* @param int $a |
36
|
|
|
* @param int $b |
37
|
|
|
* |
38
|
|
|
* @dataProvider providerForStaticIntToIntCases |
39
|
|
|
*/ |
40
|
|
|
public function testStaticIntToInt($a, $b) |
41
|
|
|
{ |
42
|
|
|
$this->assertInternalType('int', $a); |
43
|
|
|
$this->assertInternalType('int', $b); |
44
|
|
|
|
45
|
|
|
$baseExpression = new Node\Expr\BinaryOp\NotIdentical( |
46
|
|
|
new Node\Scalar\LNumber($a), |
47
|
|
|
new Node\Scalar\LNumber($b) |
48
|
|
|
); |
49
|
|
|
$compiledExpression = $this->compileExpression($baseExpression, $this->getContext()); |
50
|
|
|
|
51
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
52
|
|
|
$this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType()); |
53
|
|
|
$this->assertSame(true, $compiledExpression->getValue()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Tests (float) {left-expr} !== (float) {right-expr} |
58
|
|
|
* |
59
|
|
|
* @param int $a |
60
|
|
|
* @param int $b |
61
|
|
|
* |
62
|
|
|
* @dataProvider providerForStaticIntToIntCases |
63
|
|
|
*/ |
64
|
|
|
public function testStaticFloatToFloat($a, $b) |
65
|
|
|
{ |
66
|
|
|
$a = (float) $a; |
67
|
|
|
$b = (float) $b; |
68
|
|
|
|
69
|
|
|
$this->assertInternalType('double', $a); |
70
|
|
|
$this->assertInternalType('double', $b); |
71
|
|
|
|
72
|
|
|
$baseExpression = new Node\Expr\BinaryOp\NotIdentical( |
73
|
|
|
/** |
74
|
|
|
* Cheating - float casting |
75
|
|
|
*/ |
76
|
|
|
new Node\Scalar\DNumber($a), |
77
|
|
|
new Node\Scalar\DNumber($b) |
78
|
|
|
); |
79
|
|
|
$compiledExpression = $this->compileExpression($baseExpression, $this->getContext()); |
80
|
|
|
|
81
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
82
|
|
|
$this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType()); |
83
|
|
|
$this->assertSame(true, $compiledExpression->getValue()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function providerForStaticIntToFloatCases() |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
|
|
[-1, -1.0], |
90
|
|
|
[-5, -5.0], |
91
|
|
|
[-150, -150.0], |
92
|
|
|
[150, 150.0], |
93
|
|
|
[150, 150.0], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Tests (int) {left-expr} !== (float) {right-expr} |
99
|
|
|
* |
100
|
|
|
* @param int $a |
101
|
|
|
* @param int $b |
102
|
|
|
* |
103
|
|
|
* @dataProvider providerForStaticIntToFloatCases |
104
|
|
|
*/ |
105
|
|
|
public function testStaticIntToFloat($a, $b) |
106
|
|
|
{ |
107
|
|
|
$b = (float) $b; |
108
|
|
|
|
109
|
|
|
$this->assertInternalType('int', $a); |
110
|
|
|
$this->assertInternalType('double', $b); |
111
|
|
|
|
112
|
|
|
$baseExpression = new Node\Expr\BinaryOp\NotIdentical( |
113
|
|
|
new Node\Scalar\LNumber($a), |
114
|
|
|
new Node\Scalar\DNumber($b) |
115
|
|
|
); |
116
|
|
|
$compiledExpression = $this->compileExpression($baseExpression, $this->getContext()); |
117
|
|
|
|
118
|
|
|
$this->assertInstanceOfCompiledExpression($compiledExpression); |
119
|
|
|
$this->assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType()); |
120
|
|
|
$this->assertSame(true, $compiledExpression->getValue()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param Node\Scalar $a |
125
|
|
|
* @param Node\Scalar $b |
126
|
|
|
* @return Node\Expr\BinaryOp\NotIdentical |
127
|
|
|
*/ |
128
|
|
|
protected function buildExpression($a, $b) |
129
|
|
|
{ |
130
|
|
|
return new Node\Expr\BinaryOp\NotIdentical($a, $b); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|