1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace ParamProcessor\Tests\Integration\Types; |
6
|
|
|
|
7
|
|
|
use ParamProcessor\ParameterTypes; |
8
|
|
|
|
9
|
|
|
class IntegerTypeTest extends TypeTestBase { |
10
|
|
|
|
11
|
|
|
public function testNonStringValue() { |
12
|
|
|
$this->assertIntegerValidation( 42, 42 ); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
private function assertIntegerValidation( $expected, $input, array $definitionExtras = [] ) { |
16
|
|
|
$parameters = $this->process( |
17
|
|
|
[ |
18
|
|
|
'amount' => array_merge( |
19
|
|
|
[ |
20
|
|
|
'type' => ParameterTypes::INTEGER, |
21
|
|
|
'message' => 'test-message' |
22
|
|
|
], |
23
|
|
|
$definitionExtras |
24
|
|
|
) |
25
|
|
|
], |
26
|
|
|
[ |
27
|
|
|
'amount' => $input, |
28
|
|
|
] |
29
|
|
|
)->getParameterArray(); |
30
|
|
|
|
31
|
|
|
$this->assertSame( $expected, $parameters['amount'] ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testNonStringValueDefaultsWhenExceedingUpperBound() { |
35
|
|
|
$this->assertIntegerValidation( 7, 42, [ 'upperbound' => 20, 'default' => 7 ] ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testNonStringDefault() { |
39
|
|
|
$this->assertIntegerValidation( '7', 'NAN', [ 'default' => '7' ] ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testNoNegatives() { |
43
|
|
|
$this->assertIntegerValidation( 7, -1, [ 'negatives' => false, 'default' => 7 ] ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testNegative() { |
47
|
|
|
$this->assertIntegerValidation( -1, -1 ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testNonStringValueWithDefault() { |
51
|
|
|
$this->assertIntegerValidation( 7, 42, [ 'default' => 7 ] ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testSmwOffsetDefinition() { |
55
|
|
|
$this->assertIntegerValidation( |
56
|
|
|
0, |
57
|
|
|
42, |
58
|
|
|
[ |
59
|
|
|
'default' => 0, |
60
|
|
|
'negatives' => false, |
61
|
|
|
'upperbound' => 5000, |
62
|
|
|
] |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|