|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TraderInteractive\Filter; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @coversDefaultClass \TraderInteractive\Filter\UnsignedInt |
|
9
|
|
|
*/ |
|
10
|
|
|
final class UnsignedIntTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @test |
|
14
|
|
|
* @covers ::filter |
|
15
|
|
|
* @expectedException \InvalidArgumentException |
|
16
|
|
|
* @expectedExceptionMessage -1 was not greater or equal to zero |
|
17
|
|
|
*/ |
|
18
|
|
|
public function filterMinValueNegative() |
|
19
|
|
|
{ |
|
20
|
|
|
UnsignedInt::filter('1', false, -1); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @test |
|
25
|
|
|
* @covers ::filter |
|
26
|
|
|
*/ |
|
27
|
|
|
public function filterMinValueNullSuccess() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertSame(1, UnsignedInt::filter('1', false, null)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @test |
|
34
|
|
|
* @covers ::filter |
|
35
|
|
|
* @expectedException \TraderInteractive\Filter\Exception |
|
36
|
|
|
* @expectedExceptionMessage -1 is less than 0 |
|
37
|
|
|
*/ |
|
38
|
|
|
public function filterMinValueNullFail() |
|
39
|
|
|
{ |
|
40
|
|
|
UnsignedInt::filter('-1', false, null); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
* @covers ::filter |
|
46
|
|
|
*/ |
|
47
|
|
|
public function filterBasicUse() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertSame(123, UnsignedInt::filter('123')); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @test |
|
54
|
|
|
* @covers ::filter |
|
55
|
|
|
*/ |
|
56
|
|
|
public function filterAllowNullSuccess() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->assertSame(null, UnsignedInt::filter(null, true)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @test |
|
63
|
|
|
* @covers ::filter |
|
64
|
|
|
* @expectedException \TraderInteractive\Filter\Exception |
|
65
|
|
|
* @expectedExceptionMessage "NULL" $value is not a string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function filterAllowNullFail() |
|
68
|
|
|
{ |
|
69
|
|
|
UnsignedInt::filter(null, false); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @test |
|
74
|
|
|
* @covers ::filter |
|
75
|
|
|
* @expectedException \TraderInteractive\Filter\Exception |
|
76
|
|
|
* @expectedExceptionMessage 0 is less than 1 |
|
77
|
|
|
*/ |
|
78
|
|
|
public function filterMinValueFail() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->assertSame(1, UnsignedInt::filter('0', false, 1)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @test |
|
85
|
|
|
* @covers ::filter |
|
86
|
|
|
* @expectedException \TraderInteractive\Filter\Exception |
|
87
|
|
|
* @expectedExceptionMessage 2 is greater than 1 |
|
88
|
|
|
*/ |
|
89
|
|
|
public function filterMaxValueFail() |
|
90
|
|
|
{ |
|
91
|
|
|
UnsignedInt::filter('2', false, 0, 1); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|