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
|
|
|
*/ |
17
|
|
|
public function filterMinValueNegative() |
18
|
|
|
{ |
19
|
|
|
$this->expectException(\InvalidArgumentException::class); |
20
|
|
|
$this->expectExceptionMessage('-1 was not greater or equal to zero'); |
21
|
|
|
UnsignedInt::filter('1', false, -1); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @test |
26
|
|
|
* @covers ::filter |
27
|
|
|
*/ |
28
|
|
|
public function filterMinValueDefaultSuccess() |
29
|
|
|
{ |
30
|
|
|
$this->assertSame(1, UnsignedInt::filter('1', false)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
* @covers ::filter |
36
|
|
|
*/ |
37
|
|
|
public function filterMinValueDefaultFail() |
38
|
|
|
{ |
39
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
40
|
|
|
$this->expectExceptionMessage('-1 is less than 0'); |
41
|
|
|
UnsignedInt::filter('-1', false); |
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
|
|
|
*/ |
66
|
|
|
public function filterAllowNullFail() |
67
|
|
|
{ |
68
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
69
|
|
|
$this->expectExceptionMessage('Value failed filtering, $allowNull is set to false'); |
70
|
|
|
UnsignedInt::filter(null, false); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @test |
75
|
|
|
* @covers ::filter |
76
|
|
|
*/ |
77
|
|
|
public function filterMinValueFail() |
78
|
|
|
{ |
79
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
80
|
|
|
$this->expectExceptionMessage('0 is less than 1'); |
81
|
|
|
$this->assertSame(1, UnsignedInt::filter('0', false, 1)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @test |
86
|
|
|
* @covers ::filter |
87
|
|
|
*/ |
88
|
|
|
public function filterMaxValueFail() |
89
|
|
|
{ |
90
|
|
|
$this->expectException(\TraderInteractive\Exceptions\FilterException::class); |
91
|
|
|
$this->expectExceptionMessage('2 is greater than 1'); |
92
|
|
|
UnsignedInt::filter('2', false, 0, 1); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|