Completed
Pull Request — master (#1)
by Chad
03:07
created

FloatsTest::filterWhitespaceString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \TraderInteractive\Filter\Floats
9
 */
10
final class FloatsTest extends TestCase
11
{
12
    /**
13
     * @test
14
     * @covers ::filter
15
     */
16
    public function filterAllowNullIsTrueAndNullValue()
17
    {
18
        $this->assertNull(Floats::filter(null, true));
0 ignored issues
show
Bug introduced by
Are you sure the usage of TraderInteractive\Filter...ats::filter(null, true) targeting TraderInteractive\Filter\Floats::filter() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

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