|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace ValueParsers\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use DataValues\NumberValue; |
|
8
|
|
|
use ValueParsers\IntParser; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers \ValueParsers\IntParser |
|
12
|
|
|
* @covers \ValueParsers\StringValueParser |
|
13
|
|
|
* |
|
14
|
|
|
* @group ValueParsers |
|
15
|
|
|
* @group DataValueExtensions |
|
16
|
|
|
* |
|
17
|
|
|
* @license GPL-2.0-or-later |
|
18
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
19
|
|
|
*/ |
|
20
|
|
|
class IntParserTest extends StringValueParserTest { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @see ValueParserTestBase::getInstance |
|
24
|
|
|
* |
|
25
|
|
|
* @return IntParser |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function getInstance() { |
|
28
|
|
|
return new IntParser(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @see ValueParserTestBase::validInputProvider |
|
33
|
|
|
*/ |
|
34
|
|
|
public function validInputProvider() { |
|
35
|
|
|
return [ |
|
36
|
|
|
[ '0', new NumberValue( 0 ) ], |
|
37
|
|
|
[ '1', new NumberValue( 1 ) ], |
|
38
|
|
|
[ '42', new NumberValue( 42 ) ], |
|
39
|
|
|
[ '01', new NumberValue( 01 ) ], |
|
40
|
|
|
[ '9001', new NumberValue( 9001 ) ], |
|
41
|
|
|
[ '-1', new NumberValue( -1 ) ], |
|
42
|
|
|
[ '-42', new NumberValue( -42 ) ], |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @see StringValueParserTest::invalidInputProvider |
|
48
|
|
|
*/ |
|
49
|
|
|
public function invalidInputProvider() { |
|
50
|
|
|
$argLists = parent::invalidInputProvider(); |
|
51
|
|
|
|
|
52
|
|
|
$invalid = [ |
|
53
|
|
|
'foo', |
|
54
|
|
|
'4.2', |
|
55
|
|
|
'', |
|
56
|
|
|
'--1', |
|
57
|
|
|
'1-', |
|
58
|
|
|
'1 1', |
|
59
|
|
|
'1,', |
|
60
|
|
|
',1', |
|
61
|
|
|
',1,', |
|
62
|
|
|
'one', |
|
63
|
|
|
'0x20', |
|
64
|
|
|
'+1', |
|
65
|
|
|
'1+1', |
|
66
|
|
|
'1-1', |
|
67
|
|
|
'1.2.3', |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
|
|
foreach ( $invalid as $value ) { |
|
71
|
|
|
$argLists[] = [ $value ]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $argLists; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|