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