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

InsertStatementTest::testBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 36
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 65
rs 9.344

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\Builder;
4
5
use PhpMyAdmin\SqlParser\Parser;
6
use PhpMyAdmin\SqlParser\Tests\TestCase;
7
8
class InsertStatementTest extends TestCase
9
{
10
    public function testBuilder()
11
    {
12
        /* Assertion 1 */
13
        $parser = new Parser(
14
            'INSERT INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)'
15
        );
16
        $stmt = $parser->statements[0];
17
        $this->assertEquals(
18
            'INSERT INTO tbl(`col1`, `col2`, `col3`) VALUES (1, "str", 3.14)',
19
            $stmt->build()
20
        );
21
22
        /* Assertion 2 */
23
        /* Reserved keywords (with backqoutes as field name) */
24
        $parser = new Parser(
25
            'INSERT INTO tbl(`order`) VALUES (1)'
26
        );
27
        $stmt = $parser->statements[0];
28
        $this->assertEquals(
29
            'INSERT INTO tbl(`order`) VALUES (1)',
30
            $stmt->build()
31
        );
32
33
        /* Assertion 3 */
34
        /* INSERT ... SET ... */
35
        $parser = new Parser(
36
            'INSERT INTO tbl SET FOO = 1'
37
        );
38
        $stmt = $parser->statements[0];
39
        $this->assertEquals(
40
            'INSERT INTO tbl SET FOO = 1',
41
            $stmt->build()
42
        );
43
44
        /* Assertion 4 */
45
        /* INSERT ... SELECT ... */
46
        $parser = new Parser(
47
            'INSERT INTO tbl SELECT * FROM bar'
48
        );
49
        $stmt = $parser->statements[0];
50
        $this->assertEquals(
51
            'INSERT INTO tbl SELECT * FROM bar',
52
            $stmt->build()
53
        );
54
55
        /* Assertion 5 */
56
        /* INSERT ... ON DUPLICATE KEY UPDATE ... */
57
        $parser = new Parser(
58
            'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1'
59
        );
60
        $stmt = $parser->statements[0];
61
        $this->assertEquals(
62
            'INSERT INTO tbl SELECT * FROM bar ON DUPLICATE KEY UPDATE baz = 1',
63
            $stmt->build()
64
        );
65
66
        /* Assertion 6 */
67
        /* INSERT array(OPTIONS] INTO ... */
68
        $parser = new Parser(
69
            'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar'
70
        );
71
        $stmt = $parser->statements[0];
72
        $this->assertEquals(
73
            'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar',
74
            $stmt->build()
75
        );
76
    }
77
}
78