Conditions | 1 |
Paths | 1 |
Total Lines | 146 |
Code Lines | 102 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
52 | public function testIndex(): void |
||
53 | { |
||
54 | $binaryLogs = [ |
||
55 | [ |
||
56 | 'Log_name' => 'index1', |
||
57 | 'File_size' => 100, |
||
58 | ], |
||
59 | [ |
||
60 | 'Log_name' => 'index2', |
||
61 | 'File_size' => 200, |
||
62 | ], |
||
63 | ]; |
||
64 | $result = [ |
||
65 | [ |
||
66 | "SHOW BINLOG EVENTS IN 'index1' LIMIT 3, 10", |
||
67 | null, |
||
68 | 1, |
||
69 | true, |
||
70 | ['log1' => 'logd'], |
||
71 | ], |
||
72 | [ |
||
73 | ['log2' => 'logb'], |
||
74 | null, |
||
75 | 0, |
||
76 | false, |
||
77 | 'executed', |
||
78 | ], |
||
79 | ]; |
||
80 | $value = [ |
||
81 | 'Info' => 'index1_Info', |
||
82 | 'Log_name' => 'index1_Log_name', |
||
83 | 'Pos' => 'index1_Pos', |
||
84 | 'Event_type' => 'index1_Event_type', |
||
85 | 'Orig_log_pos' => 'index1_Orig_log_pos', |
||
86 | 'End_log_pos' => 'index1_End_log_pos', |
||
87 | 'Server_id' => 'index1_Server_id', |
||
88 | ]; |
||
89 | $count = 3; |
||
90 | |||
91 | $dbi = $this->getMockBuilder(DatabaseInterface::class) |
||
92 | ->disableOriginalConstructor() |
||
93 | ->getMock(); |
||
94 | $dbi->expects($this->once())->method('fetchResult') |
||
95 | ->will($this->returnValue($binaryLogs)); |
||
96 | $dbi->expects($this->once())->method('query') |
||
97 | ->will($this->returnValue($result)); |
||
98 | $dbi->expects($this->once())->method('numRows') |
||
99 | ->will($this->returnValue($count)); |
||
100 | $dbi->expects($this->at(3))->method('fetchAssoc') |
||
101 | ->will($this->returnValue($value)); |
||
102 | $dbi->expects($this->at(4))->method('fetchAssoc') |
||
103 | ->will($this->returnValue(false)); |
||
104 | |||
105 | $controller = new ServerBinlogController( |
||
106 | Response::getInstance(), |
||
107 | $dbi |
||
108 | ); |
||
109 | $actual = $controller->indexAction([ |
||
110 | 'log' => 'index1', |
||
111 | 'pos' => '3', |
||
112 | 'is_full_query' => null, |
||
113 | ]); |
||
114 | |||
115 | $this->assertContains( |
||
116 | 'Select binary log to view', |
||
117 | $actual |
||
118 | ); |
||
119 | $this->assertContains( |
||
120 | '<option value="index1" selected>', |
||
121 | $actual |
||
122 | ); |
||
123 | $this->assertContains( |
||
124 | '<option value="index2">', |
||
125 | $actual |
||
126 | ); |
||
127 | |||
128 | $this->assertContains( |
||
129 | 'Your SQL query has been executed successfully', |
||
130 | $actual |
||
131 | ); |
||
132 | |||
133 | $this->assertContains( |
||
134 | "SHOW BINLOG EVENTS IN 'index1' LIMIT 3, 10", |
||
135 | $actual |
||
136 | ); |
||
137 | |||
138 | $this->assertContains( |
||
139 | '<table id="binlogTable">', |
||
140 | $actual |
||
141 | ); |
||
142 | |||
143 | $urlNavigation = 'server_binlog.php" data-post="pos=3&' |
||
144 | . 'is_full_query=1&server=1&'; |
||
145 | $this->assertContains( |
||
146 | $urlNavigation, |
||
147 | $actual |
||
148 | ); |
||
149 | $this->assertContains( |
||
150 | 'title="Previous"', |
||
151 | $actual |
||
152 | ); |
||
153 | |||
154 | $this->assertContains( |
||
155 | 'Log name', |
||
156 | $actual |
||
157 | ); |
||
158 | $this->assertContains( |
||
159 | 'Position', |
||
160 | $actual |
||
161 | ); |
||
162 | $this->assertContains( |
||
163 | 'Event type', |
||
164 | $actual |
||
165 | ); |
||
166 | $this->assertContains( |
||
167 | 'Server ID', |
||
168 | $actual |
||
169 | ); |
||
170 | $this->assertContains( |
||
171 | 'Original position', |
||
172 | $actual |
||
173 | ); |
||
174 | |||
175 | $this->assertContains( |
||
176 | $value['Log_name'], |
||
177 | $actual |
||
178 | ); |
||
179 | $this->assertContains( |
||
180 | $value['Pos'], |
||
181 | $actual |
||
182 | ); |
||
183 | $this->assertContains( |
||
184 | $value['Event_type'], |
||
185 | $actual |
||
186 | ); |
||
187 | $this->assertContains( |
||
188 | $value['Server_id'], |
||
189 | $actual |
||
190 | ); |
||
191 | $this->assertContains( |
||
192 | $value['Orig_log_pos'], |
||
193 | $actual |
||
194 | ); |
||
195 | $this->assertContains( |
||
196 | $value['Info'], |
||
197 | $actual |
||
198 | ); |
||
201 |