| 1 | <?php |
||
| 10 | class ArrayParserTest extends TestCase |
||
| 11 | { |
||
| 12 | public function provideInvalidData() |
||
| 13 | { |
||
| 14 | return [ |
||
| 15 | 'empty string' => [ |
||
| 16 | 'input' => '', |
||
| 17 | ], |
||
| 18 | 'not array' => [ |
||
| 19 | 'input' => 'N;', |
||
| 20 | ], |
||
| 21 | 'array length is missing' => [ |
||
| 22 | 'input' => 'a::{}', |
||
| 23 | ], |
||
| 24 | 'array length is not number' => [ |
||
| 25 | 'input' => 'a:s:{}', |
||
| 26 | ], |
||
| 27 | 'array length is not integer' => [ |
||
| 28 | 'input' => 'a:1.0:{}', |
||
| 29 | ], |
||
| 30 | 'array length is negative' => [ |
||
| 31 | 'input' => 'a:-1:{}', |
||
| 32 | ], |
||
| 33 | 'array length is smaller than actual items' => [ |
||
| 34 | 'input' => 'a:0:{i:0;s:1:"a";}', |
||
| 35 | ], |
||
| 36 | 'array length is greater than actual items' => [ |
||
| 37 | 'input' => 'a:2:{i:0;s:1:"a";}', |
||
| 38 | ], |
||
| 39 | 'array key is not integer nor string' => [ |
||
| 40 | 'input' => 'a:1:{N;i:0;}', |
||
| 41 | ], |
||
| 42 | 'open brace not exist' => [ |
||
| 43 | 'input' => 'a:0:}', |
||
| 44 | ], |
||
| 45 | 'close brace not exist' => [ |
||
| 46 | 'input' => 'a:0:{', |
||
| 47 | ], |
||
| 48 | 'braces not exist' => [ |
||
| 49 | 'input' => 'a:0:', |
||
| 50 | ], |
||
| 51 | 'value not exist' => [ |
||
| 52 | 'input' => 'a:1:{i:0;}', |
||
| 53 | ], |
||
| 54 | ]; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @covers \xKerman\Restricted\ArrayParser |
||
| 59 | * @dataProvider provideInvalidData |
||
| 60 | * @expectedException \xKerman\Restricted\UnserializeFailedException |
||
| 61 | */ |
||
| 62 | public function testParseFailure($input) |
||
| 63 | { |
||
| 64 | $source = new Source($input); |
||
| 65 | $parser = new ArrayParser(); |
||
| 66 | $parser->parse($source); |
||
| 67 | } |
||
| 68 | } |
||
| 69 |