1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TraderInteractive\Filter; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @coversDefaultClass \TraderInteractive\Filter\Floats |
9
|
|
|
* @covers ::<private> |
10
|
|
|
*/ |
11
|
|
|
final class FloatsTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @test |
15
|
|
|
* @covers ::filter |
16
|
|
|
*/ |
17
|
|
|
public function filterAllowNullIsTrueAndNullValue() |
18
|
|
|
{ |
19
|
|
|
$this->assertNull(Floats::filter(null, true)); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
* @covers ::filter |
25
|
|
|
*/ |
26
|
|
|
public function filterPositiveFloat() |
27
|
|
|
{ |
28
|
|
|
$this->assertSame(123.0, Floats::filter(123.0)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
* @covers ::filter |
34
|
|
|
*/ |
35
|
|
|
public function filterNegativeFloat() |
36
|
|
|
{ |
37
|
|
|
$this->assertSame(-123.0, Floats::filter(-123.0)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
* @covers ::filter |
43
|
|
|
*/ |
44
|
|
|
public function filterZeroFloat() |
45
|
|
|
{ |
46
|
|
|
$positiveZero = + 0.0; |
47
|
|
|
$this->assertSame(0.0, Floats::filter($positiveZero)); |
48
|
|
|
$this->assertSame(-0.0, Floats::filter(-0.0)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
* @covers ::filter |
54
|
|
|
*/ |
55
|
|
|
public function filterPositiveString() |
56
|
|
|
{ |
57
|
|
|
$this->assertSame(123.0, Floats::filter(' 123 ')); |
58
|
|
|
$this->assertSame(123.0, Floats::filter(' +123 ')); |
59
|
|
|
$this->assertSame(123.0, Floats::filter(' 123.0 ')); |
60
|
|
|
$this->assertSame(123.0, Floats::filter(' 123E0 ')); |
61
|
|
|
$this->assertSame(123.0, Floats::filter(' +123e0 ')); |
62
|
|
|
$this->assertSame(123.0, Floats::filter(' +1230e-1 ')); |
63
|
|
|
$this->assertSame(1230.0, Floats::filter(' +123e+1 ')); |
64
|
|
|
$this->assertSame(0.0, Floats::filter(' +0 ')); |
65
|
|
|
$this->assertSame(0.0, Floats::filter(' +0.0 ')); |
66
|
|
|
$this->assertSame(0.0, Floats::filter(' 0E0 ')); |
67
|
|
|
$this->assertSame(0.0, Floats::filter(' 00e-1 ')); |
68
|
|
|
$this->assertSame(0.0, Floats::filter(' 00e+1 ')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @test |
73
|
|
|
* @covers ::filter |
74
|
|
|
*/ |
75
|
|
|
public function filterNegativeString() |
76
|
|
|
{ |
77
|
|
|
$this->assertSame(-123.0, Floats::filter(' -123 ')); |
78
|
|
|
$this->assertSame(-123.0, Floats::filter(' -123.0 ')); |
79
|
|
|
$this->assertSame(-123.0, Floats::filter(' -123E0 ')); |
80
|
|
|
$this->assertSame(-123.0, Floats::filter(' -1230E-1 ')); |
81
|
|
|
$this->assertSame(-1230.0, Floats::filter(' -123e+1 ')); |
82
|
|
|
$this->assertSame(-0.0, Floats::filter(' -0 ')); |
83
|
|
|
$this->assertSame(-0.0, Floats::filter(' -0.0 ')); |
84
|
|
|
$this->assertSame(-0.0, Floats::filter(' -0e0 ')); |
85
|
|
|
$this->assertSame(-0.0, Floats::filter(' -00e-1 ')); |
86
|
|
|
$this->assertSame(-0.0, Floats::filter(' -0e+1 ')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @test |
91
|
|
|
* @covers ::filter |
92
|
|
|
*/ |
93
|
|
|
public function filterNonStringOrFloat() |
94
|
|
|
{ |
95
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
96
|
|
|
$this->expectExceptionMessage('"true" $value is not a string'); |
97
|
|
|
Floats::filter(true); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @test |
102
|
|
|
* @covers ::filter |
103
|
|
|
*/ |
104
|
|
|
public function filterEmptyString() |
105
|
|
|
{ |
106
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
107
|
|
|
$this->expectExceptionMessage(' does not pass is_numeric'); |
108
|
|
|
Floats::filter(''); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @test |
113
|
|
|
* @covers ::filter |
114
|
|
|
*/ |
115
|
|
|
public function filterWhitespaceString() |
116
|
|
|
{ |
117
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
118
|
|
|
$this->expectExceptionMessage(' does not pass is_numeric'); |
119
|
|
|
Floats::filter(' '); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @test |
124
|
|
|
* @covers ::filter |
125
|
|
|
*/ |
126
|
|
|
public function filterNonDigitString() |
127
|
|
|
{ |
128
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
129
|
|
|
$this->expectExceptionMessage('123-4 does not pass is_numeric'); |
130
|
|
|
Floats::filter('123-4'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @test |
135
|
|
|
* @covers ::filter |
136
|
|
|
*/ |
137
|
|
|
public function filterHexString() |
138
|
|
|
{ |
139
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
140
|
|
|
Floats::filter('0xFF'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @test |
145
|
|
|
* @covers ::filter |
146
|
|
|
*/ |
147
|
|
|
public function filterRogueSpaceStringAfterPeriod() |
148
|
|
|
{ |
149
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
150
|
|
|
$this->expectExceptionMessage('1. 0 does not pass is_numeric'); |
151
|
|
|
Floats::filter('1. 0'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @test |
156
|
|
|
* @covers ::filter |
157
|
|
|
*/ |
158
|
|
|
public function filterRogueSpaceStringBetweenDigits() |
159
|
|
|
{ |
160
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
161
|
|
|
$this->expectExceptionMessage('1 0 does not pass is_numeric'); |
162
|
|
|
Floats::filter('1 0'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @test |
167
|
|
|
* @covers ::filter |
168
|
|
|
*/ |
169
|
|
|
public function filterOverflow() |
170
|
|
|
{ |
171
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
172
|
|
|
$this->expectExceptionMessage('1e999999999999 overflow'); |
173
|
|
|
Floats::filter('1e999999999999'); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @test |
178
|
|
|
* @covers ::filter |
179
|
|
|
*/ |
180
|
|
|
public function filterUnderflow() |
181
|
|
|
{ |
182
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
183
|
|
|
$this->expectExceptionMessage('-1e999999999999 overflow'); |
184
|
|
|
Floats::filter('-1e999999999999'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @test |
189
|
|
|
* @covers ::filter |
190
|
|
|
*/ |
191
|
|
|
public function filterLessThanMin() |
192
|
|
|
{ |
193
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
194
|
|
|
$this->expectExceptionMessage('-1 is less than 0'); |
195
|
|
|
Floats::filter(-1.0, false, 0.0); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @test |
200
|
|
|
* @covers ::filter |
201
|
|
|
*/ |
202
|
|
|
public function filterEqualToMin() |
203
|
|
|
{ |
204
|
|
|
$this->assertSame(0.0, Floats::filter(0.0, false, 0.0)); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @test |
209
|
|
|
* @covers ::filter |
210
|
|
|
*/ |
211
|
|
|
public function filterGreaterThanMax() |
212
|
|
|
{ |
213
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
214
|
|
|
$this->expectExceptionMessage('1 is greater than 0'); |
215
|
|
|
Floats::filter(1.0, false, null, 0.0); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @test |
220
|
|
|
* @covers ::filter |
221
|
|
|
*/ |
222
|
|
|
public function filterEqualToMax() |
223
|
|
|
{ |
224
|
|
|
$this->assertSame(0.0, Floats::filter(0.0, false, null, 0.0)); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @test |
229
|
|
|
* @covers ::filter |
230
|
|
|
*/ |
231
|
|
|
public function filterCastInts() |
232
|
|
|
{ |
233
|
|
|
$this->assertSame(1.0, Floats::filter(1, false, null, null, true)); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @test |
238
|
|
|
* @covers ::filter |
239
|
|
|
*/ |
240
|
|
|
public function filterCastIntsIsFalse() |
241
|
|
|
{ |
242
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
243
|
|
|
$this->expectExceptionMessage('"1" $value is not a string'); |
244
|
|
|
Floats::filter(1, false, null, null, false); |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.