Passed
Pull Request — master (#311)
by William
12:43
created

Array2dTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
c 1
b 0
f 0
dl 0
loc 97
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseErr5() 0 11 1
A testParseErr4() 0 11 1
A testParse() 0 10 1
A testParseErr3() 0 11 1
A testParseErr2() 0 7 1
A testParseErr1() 0 7 1
A testBuild() 0 6 1
A testParseErr6() 0 11 1
1
<?php
2
3
namespace PhpMyAdmin\SqlParser\Tests\Components;
4
5
use PhpMyAdmin\SqlParser\Components\Array2d;
6
use PhpMyAdmin\SqlParser\Parser;
7
use PhpMyAdmin\SqlParser\Tests\TestCase;
8
9
class Array2dTest extends TestCase
10
{
11
    public function testParse()
12
    {
13
        $parser = new Parser();
14
        $arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +'));
15
        $this->assertEquals(
16
            array(
17
                1,
18
                2,
19
            ),
20
            $arrays[0]->values
21
        );
22
    }
23
24
    public function testBuild()
25
    {
26
        $arrays = Array2d::parse(new Parser(), $this->getTokensList('(1, 2), (3, 4), (5, 6)'));
27
        $this->assertEquals(
28
            '(1, 2), (3, 4), (5, 6)',
29
            Array2d::build($arrays)
30
        );
31
    }
32
33
    public function testParseErr1()
34
    {
35
        $parser = new Parser();
36
        Array2d::parse($parser, $this->getTokensList('(1, 2 +'));
37
38
        $this->markTestIncomplete(
39
            'This test has not been implemented yet.'
40
        );
41
    }
42
43
    public function testParseErr2()
44
    {
45
        $parser = new Parser();
46
        Array2d::parse($parser, $this->getTokensList('(1, 2 TABLE'));
47
48
        $this->markTestIncomplete(
49
            'This test has not been implemented yet.'
50
        );
51
    }
52
53
    public function testParseErr3()
54
    {
55
        $parser = new Parser();
56
        Array2d::parse($parser, $this->getTokensList(')'));
57
        $this->assertCount(
58
            1,
59
            $parser->errors
60
        );
61
        $this->assertEquals(
62
            'An opening bracket followed by a set of values was expected.',
63
            $parser->errors[0]->getMessage()
64
        );
65
    }
66
67
    public function testParseErr4()
68
    {
69
        $parser = new Parser();
70
        Array2d::parse($parser, $this->getTokensList('TABLE'));
71
        $this->assertCount(
72
            1,
73
            $parser->errors
74
        );
75
        $this->assertEquals(
76
            'An opening bracket followed by a set of values was expected.',
77
            $parser->errors[0]->getMessage()
78
        );
79
    }
80
81
    public function testParseErr5()
82
    {
83
        $parser = new Parser();
84
        Array2d::parse($parser, $this->getTokensList('(1, 2),'));
85
        $this->assertCount(
86
            1,
87
            $parser->errors
88
        );
89
        $this->assertEquals(
90
            'An opening bracket followed by a set of values was expected.',
91
            $parser->errors[0]->getMessage()
92
        );
93
    }
94
95
    public function testParseErr6()
96
    {
97
        $parser = new Parser();
98
        Array2d::parse($parser, $this->getTokensList('(1, 2),(3)'));
99
        $this->assertCount(
100
            1,
101
            $parser->errors
102
        );
103
        $this->assertEquals(
104
            '2 values were expected, but found 1.',
105
            $parser->errors[0]->getMessage()
106
        );
107
    }
108
}
109