Conditions | 1 |
Paths | 1 |
Total Lines | 94 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
12 | public function testBuilder() |
||
13 | { |
||
14 | /* Assertion 1 */ |
||
15 | $query = 'LOAD DATA CONCURRENT INFILE ' |
||
16 | . '\'employee1.txt\' INTO TABLE employee'; |
||
17 | |||
18 | $parser = new Parser($query); |
||
19 | $stmt = $parser->statements[0]; |
||
20 | |||
21 | $this->assertEquals( |
||
22 | 'LOAD DATA CONCURRENT INFILE ' |
||
23 | . '\'employee1.txt\' INTO TABLE employee', |
||
24 | $stmt->build() |
||
25 | ); |
||
26 | |||
27 | /* Assertion 2 */ |
||
28 | $query = 'LOAD DATA INFILE \'/tmp/test.txt\' ' |
||
29 | . 'INTO TABLE test FIELDS TERMINATED BY ' |
||
30 | . '\',\' IGNORE 1 LINES'; |
||
31 | |||
32 | $parser = new Parser($query); |
||
33 | $stmt = $parser->statements[0]; |
||
34 | |||
35 | $this->assertEquals( |
||
36 | 'LOAD DATA INFILE \'/tmp/test.txt\' ' |
||
37 | . 'INTO TABLE test FIELDS TERMINATED BY ' |
||
38 | . '\',\' IGNORE 1 LINES', |
||
39 | $stmt->build() |
||
40 | ); |
||
41 | |||
42 | /* Assertion 3 */ |
||
43 | $query = 'LOAD DATA INFILE \'employee3.txt\' ' |
||
44 | . 'INTO TABLE employee FIELDS TERMINATED BY ' |
||
45 | . '\',\' ENCLOSED BY \'"\''; |
||
46 | |||
47 | $parser = new Parser($query); |
||
48 | $stmt = $parser->statements[0]; |
||
49 | |||
50 | $this->assertEquals( |
||
51 | 'LOAD DATA INFILE \'employee3.txt\' ' |
||
52 | . 'INTO TABLE employee FIELDS TERMINATED BY ' |
||
53 | . '\',\' ENCLOSED BY \'"\'', |
||
54 | $stmt->build() |
||
55 | ); |
||
56 | |||
57 | /* Assertion 4 */ |
||
58 | $query = 'LOAD DATA INFILE \'/tmp/test.txt\' IGNORE ' |
||
59 | . 'INTO TABLE test ' |
||
60 | . 'CHARACTER SET \'utf8\' ' |
||
61 | . 'COLUMNS TERMINATED BY \',\' ' |
||
62 | . 'LINES TERMINATED BY \';\' ' |
||
63 | . 'IGNORE 1 LINES (col1, col2) SET @a = 1'; |
||
64 | |||
65 | $parser = new Parser($query); |
||
66 | $stmt = $parser->statements[0]; |
||
67 | |||
68 | $this->assertEquals( |
||
69 | 'LOAD DATA INFILE \'/tmp/test.txt\' IGNORE ' |
||
70 | . 'INTO TABLE test ' |
||
71 | . 'CHARACTER SET \'utf8\' ' |
||
72 | . 'COLUMNS TERMINATED BY \',\' ' |
||
73 | . 'LINES TERMINATED BY \';\' ' |
||
74 | . 'IGNORE 1 LINES (col1, col2) SET @a = 1', |
||
75 | $stmt->build() |
||
76 | ); |
||
77 | |||
78 | /* Assertion 5 */ |
||
79 | $query = 'LOAD DATA INFILE \'/tmp/test.txt\' REPLACE ' |
||
80 | . 'INTO TABLE test COLUMNS TERMINATED BY \',\' IGNORE 1 ROWS'; |
||
81 | |||
82 | $parser = new Parser($query); |
||
83 | $stmt = $parser->statements[0]; |
||
84 | |||
85 | $this->assertEquals( |
||
86 | 'LOAD DATA INFILE \'/tmp/test.txt\' REPLACE ' |
||
87 | . 'INTO TABLE test COLUMNS TERMINATED BY \',\' IGNORE 1 ROWS', |
||
88 | $stmt->build() |
||
89 | ); |
||
90 | |||
91 | /* Assertion 6 */ |
||
92 | $query = 'LOAD DATA INFILE \'/tmp/test.txt\' IGNORE ' |
||
93 | . 'INTO TABLE test PARTITION (p0, p1, p2) CHARACTER SET \'utf8\' ' |
||
94 | . 'COLUMNS TERMINATED BY \',\' LINES TERMINATED BY \';\' ' |
||
95 | . 'IGNORE 1 LINES (col1, col2) SET @a = 1'; |
||
96 | |||
97 | $parser = new Parser($query); |
||
98 | $stmt = $parser->statements[0]; |
||
99 | |||
100 | $this->assertEquals( |
||
101 | 'LOAD DATA INFILE \'/tmp/test.txt\' IGNORE ' |
||
102 | . 'INTO TABLE test PARTITION (p0, p1, p2) CHARACTER SET \'utf8\' ' |
||
103 | . 'COLUMNS TERMINATED BY \',\' LINES TERMINATED BY \';\' ' |
||
104 | . 'IGNORE 1 LINES (col1, col2) SET @a = 1', |
||
105 | $stmt->build() |
||
106 | ); |
||
109 |