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

MiscTest::getAliasesProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 95
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 69
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 95
rs 8.6763

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpMyAdmin\SqlParser\Tests\Utils;
4
5
use PhpMyAdmin\SqlParser\Parser;
6
use PhpMyAdmin\SqlParser\Tests\TestCase;
7
use PhpMyAdmin\SqlParser\Utils\Misc;
8
9
class MiscTest extends TestCase
10
{
11
    /**
12
     * @dataProvider getAliasesProvider
13
     *
14
     * @param mixed $query
15
     * @param mixed $db
16
     */
17
    public function testGetAliases($query, $db, array $expected)
18
    {
19
        $parser = new Parser($query);
20
        $statement = empty($parser->statements[0]) ?
21
            null : $parser->statements[0];
22
        $this->assertEquals($expected, Misc::getAliases($statement, $db));
23
    }
24
25
    public function getAliasesProvider()
26
    {
27
        return array(
28
            array(
29
                'select * from (select 1) tbl',
30
                'mydb',
31
                array(),
32
            ),
33
            array(
34
                'select i.name as `n`,abcdef gh from qwerty i',
35
                'mydb',
36
                array(
37
                    'mydb' => array(
38
                        'alias' => null,
39
                        'tables' => array(
40
                            'qwerty' => array(
41
                                'alias' => 'i',
42
                                'columns' => array(
43
                                    'name' => 'n',
44
                                    'abcdef' => 'gh',
45
                                ),
46
                            ),
47
                        ),
48
                    ),
49
                ),
50
            ),
51
            array(
52
                'select film_id id,title from film',
53
                'sakila',
54
                array(
55
                    'sakila' => array(
56
                        'alias' => null,
57
                        'tables' => array(
58
                            'film' => array(
59
                                'alias' => null,
60
                                'columns' => array(
61
                                    'film_id' => 'id',
62
                                ),
63
                            ),
64
                        ),
65
                    ),
66
                ),
67
            ),
68
            array(
69
                'select `sakila`.`A`.`actor_id` as aid,`F`.`film_id` `fid`,'
70
                . 'last_update updated from `sakila`.actor A join `film_actor` as '
71
                . '`F` on F.actor_id = A.`actor_id`',
72
                'sakila',
73
                array(
74
                    'sakila' => array(
75
                        'alias' => null,
76
                        'tables' => array(
77
                            'film_actor' => array(
78
                                'alias' => 'F',
79
                                'columns' => array(
80
                                    'film_id' => 'fid',
81
                                    'last_update' => 'updated',
82
                                ),
83
                            ),
84
                            'actor' => array(
85
                                'alias' => 'A',
86
                                'columns' => array(
87
                                    'actor_id' => 'aid',
88
                                    'last_update' => 'updated',
89
                                ),
90
                            ),
91
                        ),
92
                    ),
93
                ),
94
            ),
95
            array(
96
                'SELECT film_id FROM (SELECT * FROM film) as f;',
97
                'sakila',
98
                array(),
99
            ),
100
            array(
101
                '',
102
                null,
103
                array(),
104
            ),
105
            array(
106
                'SELECT 1',
107
                null,
108
                array(),
109
            ),
110
            array(
111
                'SELECT * FROM orders AS ord WHERE 1',
112
                'db',
113
                array(
114
                    'db' => array(
115
                        'alias' => null,
116
                        'tables' => array(
117
                            'orders' => array(
118
                                'alias' => 'ord',
119
                                'columns' => array(),
120
                            ),
121
                        ),
122
                    ),
123
                ),
124
            )
125
        );
126
    }
127
}
128