Conditions | 1 |
Paths | 1 |
Total Lines | 122 |
Code Lines | 108 |
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 |
||
187 | public function testWithoutEvents(): void |
||
188 | { |
||
189 | $GLOBALS['server'] = 2; |
||
190 | $GLOBALS['text_dir'] = 'ltr'; |
||
191 | $GLOBALS['PMA_PHP_SELF'] = 'index.php'; |
||
192 | $GLOBALS['db'] = 'test_db'; |
||
193 | $GLOBALS['cfg']['Server']['DisableIS'] = true; |
||
194 | |||
195 | $dummyDbi = $this->createDbiDummy(); |
||
196 | // phpcs:disable Generic.Files.LineLength.TooLong |
||
197 | $dummyDbi->removeDefaultResults(); |
||
198 | $dummyDbi->addSelectDb('test_db'); |
||
199 | $dummyDbi->addResult( |
||
200 | 'SHOW EVENTS FROM `test_db`', |
||
201 | [], |
||
202 | ['Db', 'Name', 'Definer', 'Type', 'Status'], |
||
203 | ); |
||
204 | $dummyDbi->addResult('SELECT CURRENT_USER();', [['definer@localhost']], ['CURRENT_USER()']); |
||
205 | $dummyDbi->addResult( |
||
206 | "SELECT `PRIVILEGE_TYPE` FROM `INFORMATION_SCHEMA`.`USER_PRIVILEGES` WHERE GRANTEE='''definer''@''localhost''' AND PRIVILEGE_TYPE='EVENT'", |
||
207 | [['EVENT']], |
||
208 | ['PRIVILEGE_TYPE'], |
||
209 | ); |
||
210 | $dummyDbi->addResult( |
||
211 | 'SHOW GLOBAL VARIABLES LIKE \'event_scheduler\'', |
||
212 | [['event_scheduler', 'OFF']], |
||
213 | ['Variable_name', 'Value'], |
||
214 | ); |
||
215 | // phpcs:enable |
||
216 | $dbi = $this->createDatabaseInterface($dummyDbi); |
||
217 | $GLOBALS['dbi'] = $dbi; |
||
218 | $response = new ResponseRenderer(); |
||
219 | $template = new Template(); |
||
220 | |||
221 | (new EventsController( |
||
222 | $response, |
||
223 | $template, |
||
224 | new Events($dbi, $template, $response), |
||
225 | $dbi, |
||
226 | ))($this->createStub(ServerRequest::class)); |
||
227 | |||
228 | $actual = $response->getHTMLResult(); |
||
229 | // phpcs:disable Generic.Files.LineLength.TooLong |
||
230 | $expected = <<<'HTML' |
||
231 | <div class="container-fluid my-3"> |
||
232 | <h2> |
||
233 | <span class="text-nowrap"><img src="themes/dot.gif" title="Events" alt="Events" class="icon ic_b_events"> Events</span> |
||
234 | <a href="index.php?route=/url&url=https%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Fevents.html" target="mysql_doc"><img src="themes/dot.gif" title="Documentation" alt="Documentation" class="icon ic_b_help"></a> |
||
235 | </h2> |
||
236 | |||
237 | <div class="d-flex flex-wrap my-3"> |
||
238 | <div> |
||
239 | <a class="ajax add_anchor btn btn-primary" href="index.php?route=/database/events&db=test_db&add_item=1&server=2&lang=en" role="button"> |
||
240 | <span class="text-nowrap"><img src="themes/dot.gif" title="Create new event" alt="Create new event" class="icon ic_b_event_add"> Create new event</span> |
||
241 | </a> |
||
242 | </div> |
||
243 | </div> |
||
244 | |||
245 | <form id="rteListForm" class="ajax" action="index.php?route=/database/events&server=2&lang=en"> |
||
246 | <input type="hidden" name="db" value="test_db"><input type="hidden" name="server" value="2"><input type="hidden" name="lang" value="en"><input type="hidden" name="token" value="token"> |
||
247 | |||
248 | <div id="nothing2display"> |
||
249 | <div class="alert alert-primary" role="alert"> |
||
250 | <img src="themes/dot.gif" title="" alt="" class="icon ic_s_notice"> There are no events to display. |
||
251 | </div> |
||
252 | |||
253 | </div> |
||
254 | |||
255 | <table id="eventsTable" class="table table-striped table-hover hide w-auto data"> |
||
256 | <thead> |
||
257 | <tr> |
||
258 | <th></th> |
||
259 | <th>Name</th> |
||
260 | <th>Status</th> |
||
261 | <th>Type</th> |
||
262 | <th colspan="3"></th> |
||
263 | </tr> |
||
264 | </thead> |
||
265 | <tbody> |
||
266 | <tr class="hide"><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> |
||
267 | |||
268 | </tbody> |
||
269 | </table> |
||
270 | </form> |
||
271 | |||
272 | <div class="card mt-3"> |
||
273 | <div class="card-header">Event scheduler status</div> |
||
274 | <div class="card-body"> |
||
275 | <div class="wrap"> |
||
276 | <div class="wrapper toggleAjax hide"> |
||
277 | <div class="toggleButton"> |
||
278 | <div title="Click to toggle" class="toggle-container off"> |
||
279 | <img src=""> |
||
280 | <table> |
||
281 | <tbody> |
||
282 | <tr> |
||
283 | <td class="toggleOn"> |
||
284 | <span class="hide">index.php?route=/sql&db=test_db&goto=index.php%3Froute%3D%2Fdatabase%2Fevents%26db%3Dtest_db%26server%3D2%26lang%3Den&sql_query=SET+GLOBAL+event_scheduler%3D%22ON%22&server=2&lang=en</span> |
||
285 | <div>ON</div> |
||
286 | </td> |
||
287 | <td><div> </div></td> |
||
288 | <td class="toggleOff"> |
||
289 | <span class="hide">index.php?route=/sql&db=test_db&goto=index.php%3Froute%3D%2Fdatabase%2Fevents%26db%3Dtest_db%26server%3D2%26lang%3Den&sql_query=SET+GLOBAL+event_scheduler%3D%22OFF%22&server=2&lang=en</span> |
||
290 | <div>OFF</div> |
||
291 | </td> |
||
292 | </tr> |
||
293 | </tbody> |
||
294 | </table> |
||
295 | <span class="hide callback">Functions.slidingMessage(data.sql_query);</span> |
||
296 | <span class="hide text_direction">ltr</span> |
||
297 | </div> |
||
298 | </div> |
||
299 | </div> |
||
300 | </div> |
||
301 | </div> |
||
302 | </div> |
||
303 | </div> |
||
304 | |||
305 | HTML; |
||
306 | // phpcs:enable |
||
307 | |||
308 | $this->assertSame($expected, $actual); |
||
309 | } |
||
311 |