@@ 10-61 (lines=52) @@ | ||
7 | use xKerman\Restricted\IntegerParser; |
|
8 | use xKerman\Restricted\Source; |
|
9 | ||
10 | class IntegerParserTest extends TestCase |
|
11 | { |
|
12 | public function provideInvalidData() |
|
13 | { |
|
14 | return [ |
|
15 | 'empty string' => [ |
|
16 | 'input' => '', |
|
17 | ], |
|
18 | 'not integer' => [ |
|
19 | 'input' => 'N;', |
|
20 | ], |
|
21 | 'missing tag' => [ |
|
22 | 'input' => ':0;', |
|
23 | ], |
|
24 | 'missing value' => [ |
|
25 | 'input' => 'i:;', |
|
26 | ], |
|
27 | 'missing semicolon' => [ |
|
28 | 'input' => 'i:0', |
|
29 | ], |
|
30 | 'sign only' => [ |
|
31 | 'input' => 'i:+;', |
|
32 | ], |
|
33 | 'multiple sign' => [ |
|
34 | 'input' => 'i:++6;', |
|
35 | ], |
|
36 | 'float value' => [ |
|
37 | 'input' => 'i:1.0;', |
|
38 | ], |
|
39 | 'hex value' => [ |
|
40 | 'input' => 'i:0x50;', |
|
41 | ], |
|
42 | 'binary value' => [ |
|
43 | 'input' => 'i:0b111;', |
|
44 | ], |
|
45 | ]; |
|
46 | } |
|
47 | ||
48 | /** |
|
49 | * @covers \xKerman\Restricted\IntegerParser |
|
50 | * @covers \xKerman\Restricted\NumberLiteralParser |
|
51 | * @covers \xKerman\Restricted\NumberStringParser |
|
52 | * @dataProvider provideInvalidData |
|
53 | * @expectedException \xKerman\Restricted\UnserializeFailedException |
|
54 | */ |
|
55 | public function testParseFailure($input) |
|
56 | { |
|
57 | $source = new Source($input); |
|
58 | $parser = new IntegerParser(); |
|
59 | $parser->parse($source); |
|
60 | } |
|
61 | } |
|
62 |
@@ 13-62 (lines=50) @@ | ||
10 | /** |
|
11 | * @coversDefaultClass \xKerman\Restricted\StringParser |
|
12 | */ |
|
13 | class StringParserTest extends TestCase |
|
14 | { |
|
15 | public function provideInvalidData() |
|
16 | { |
|
17 | return [ |
|
18 | 'empty string' => [ |
|
19 | 'input' => '', |
|
20 | ], |
|
21 | 'non string tag' => [ |
|
22 | 'input' => 'a:0:"";', |
|
23 | ], |
|
24 | 'length is missing' => [ |
|
25 | 'input' => 's::"";', |
|
26 | ], |
|
27 | 'length is not number' => [ |
|
28 | 'input' => 's:a:"";', |
|
29 | ], |
|
30 | 'length is not integer' => [ |
|
31 | 'input' => 's:1.0:"a";', |
|
32 | ], |
|
33 | 'length is negative' => [ |
|
34 | 'input' => 's:-1:"";', |
|
35 | ], |
|
36 | 'no quote' => [ |
|
37 | 'input' => 's:1:a;', |
|
38 | ], |
|
39 | 'open quote exist but close quote not exist' => [ |
|
40 | 'input' => 's:1:"a;', |
|
41 | ], |
|
42 | 'close quote exist but open quote not exist' => [ |
|
43 | 'input' => 's:1:a";', |
|
44 | ], |
|
45 | 'enclosed by single quote' => [ |
|
46 | 'input' => "s:1:'a';", |
|
47 | ], |
|
48 | ]; |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * @covers ::parse |
|
53 | * @dataProvider provideInvalidData |
|
54 | * @expectedException \xKerman\Restricted\UnserializeFailedException |
|
55 | */ |
|
56 | public function testParseFailure($input) |
|
57 | { |
|
58 | $source = new Source($input); |
|
59 | $parser = new StringParser(); |
|
60 | $parser->parse($source); |
|
61 | } |
|
62 | } |
|
63 |