Completed
Branch feature/scrutinizer (5874ea)
by X
03:07
created

ArrayParserTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B provideInvalidData() 0 44 1
A testParseFailure() 0 6 1
1
<?php
2
3
namespace xKerman\Restricted\Test;
4
5
use PHPUnit\Framework\TestCase;
6
7
use xKerman\Restricted\ArrayParser;
8
use xKerman\Restricted\Source;
9
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