Conditions | 1 |
Paths | 1 |
Total Lines | 159 |
Code Lines | 86 |
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 |
||
224 | public function diffProvider() |
||
225 | { |
||
226 | // [ |
||
227 | // [ create database 1, create database 2, diff flags, array of statements to execute ], |
||
228 | // ... |
||
229 | // ] |
||
230 | $testCases = []; |
||
231 | |||
232 | /** @var CollationInfo|Mockery\MockInterface $collationInfo */ |
||
233 | $collationInfo = Mockery::mock(CollationInfo::class); |
||
234 | $collationInfo->shouldReceive('isSpecified'); |
||
235 | |||
236 | // Completely empty objects |
||
237 | $testCases[] = [ |
||
238 | new CreateDatabase($collationInfo), |
||
1 ignored issue
–
show
|
|||
239 | new CreateDatabase($collationInfo), |
||
240 | [], |
||
241 | [] |
||
242 | ]; |
||
243 | |||
244 | // Named databases |
||
245 | // Morphism does not support renaming databases |
||
246 | $db1 = new CreateDatabase($collationInfo); |
||
247 | $db1->name = 'foo'; |
||
248 | |||
249 | $db2 = new CreateDatabase($collationInfo); |
||
250 | $db2->name = 'bar'; |
||
251 | |||
252 | $testCases[] = [ |
||
253 | $db1, |
||
254 | $db2, |
||
255 | [], |
||
256 | [] |
||
257 | ]; |
||
258 | |||
259 | // Table added |
||
260 | $db1 = new CreateDatabase($collationInfo); |
||
261 | |||
262 | /** @var CreateTable|Mockery\MockInterface $tableA */ |
||
263 | $tableA = Mockery::mock(CreateTable::class); |
||
264 | $tableA->shouldReceive('getName')->andReturn('t'); |
||
265 | $tableA->shouldReceive('getDDL')->andReturn(["CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL\n) ENGINE=E"]); |
||
266 | |||
267 | $db2 = new CreateDatabase($collationInfo); |
||
268 | $db2->addTable($tableA); |
||
1 ignored issue
–
show
|
|||
269 | |||
270 | $testCases[] = [ |
||
271 | $db1, |
||
272 | $db2, |
||
273 | [], |
||
274 | ["CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL\n) ENGINE=E"] |
||
275 | ]; |
||
276 | |||
277 | // Table added |
||
278 | $db1 = new CreateDatabase($collationInfo); |
||
279 | |||
280 | $db2 = new CreateDatabase($collationInfo); |
||
281 | $db2->addTable($tableA); |
||
282 | |||
283 | $testCases[] = [ |
||
284 | $db1, |
||
285 | $db2, |
||
286 | [], |
||
287 | ["CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL\n) ENGINE=E"] |
||
288 | ]; |
||
289 | |||
290 | // Table added (but ignored) |
||
291 | $db1 = new CreateDatabase($collationInfo); |
||
292 | |||
293 | $db2 = new CreateDatabase($collationInfo); |
||
294 | $db2->addTable($tableA); |
||
295 | |||
296 | $testCases[] = [ |
||
297 | $db1, |
||
298 | $db2, |
||
299 | ['createTable' => false], |
||
300 | [] |
||
301 | ]; |
||
302 | |||
303 | // Table removed |
||
304 | $db1 = new CreateDatabase($collationInfo); |
||
305 | $db1->addTable($tableA); |
||
306 | |||
307 | $db2 = new CreateDatabase($collationInfo); |
||
308 | |||
309 | $testCases[] = [ |
||
310 | $db1, |
||
311 | $db2, |
||
312 | [], |
||
313 | ["DROP TABLE IF EXISTS `t`"] |
||
314 | ]; |
||
315 | |||
316 | // Table removed (but ignored) |
||
317 | $db1 = new CreateDatabase($collationInfo); |
||
318 | $db1->addTable($tableA); |
||
319 | |||
320 | $db2 = new CreateDatabase($collationInfo); |
||
321 | |||
322 | $testCases[] = [ |
||
323 | $db1, |
||
324 | $db2, |
||
325 | ['dropTable' => false], |
||
326 | [] |
||
327 | ]; |
||
328 | |||
329 | // Engine changed |
||
330 | /** @var CreateTable|Mockery\MockInterface $tableWithEngineBar */ |
||
331 | $tableWithEngineBar = Mockery::mock(CreateTable::class); |
||
332 | $tableWithEngineBar->shouldReceive('getName')->andReturn('t'); |
||
333 | $tableWithEngineBar->shouldReceive('getDDL')->andReturn(["CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL\n) ENGINE=BAR"]); |
||
334 | |||
335 | /** @var CreateTable|Mockery\MockInterface $tableWithEngineFoo */ |
||
336 | $tableWithEngineFoo = Mockery::mock(CreateTable::class); |
||
337 | $tableWithEngineFoo->shouldReceive('getName')->andReturn('t'); |
||
338 | $tableWithEngineFoo->shouldReceive('getDDL')->andReturn(["CREATE TABLE `t` (\n `a` int(11) DEFAULT NULL\n) ENGINE=FOO"]); |
||
339 | $tableWithEngineFoo |
||
340 | ->shouldReceive('diff') |
||
341 | ->with( |
||
342 | $tableWithEngineBar, |
||
343 | ['alterEngine' => true] |
||
344 | ) |
||
345 | ->andReturn(["ALTER TABLE `t`\nENGINE=BAR"]); |
||
346 | |||
347 | $db1 = new CreateDatabase($collationInfo); |
||
348 | $db1->addTable($tableWithEngineFoo); |
||
349 | |||
350 | $db2 = new CreateDatabase($collationInfo); |
||
351 | $db2->addTable($tableWithEngineBar); |
||
352 | |||
353 | $testCases[] = [ |
||
354 | $db1, |
||
355 | $db2, |
||
356 | [], |
||
357 | ["ALTER TABLE `t`\nENGINE=BAR"] |
||
358 | ]; |
||
359 | |||
360 | // Engine changed (but ignored) |
||
361 | $db1 = new CreateDatabase($collationInfo); |
||
362 | $db1->addTable($tableWithEngineFoo); |
||
363 | |||
364 | $tableWithEngineFoo |
||
365 | ->shouldReceive('diff') |
||
1 ignored issue
–
show
|
|||
366 | ->with( |
||
367 | $tableWithEngineBar, |
||
368 | ['alterEngine' => false] |
||
369 | ) |
||
370 | ->andReturn([]); |
||
371 | |||
372 | $db2 = new CreateDatabase($collationInfo); |
||
373 | $db2->addTable($tableWithEngineBar); |
||
374 | |||
375 | $testCases[] = [ |
||
376 | $db1, |
||
377 | $db2, |
||
378 | ['alterEngine' => false], |
||
379 | [] |
||
380 | ]; |
||
381 | |||
382 | return $testCases; |
||
383 | } |
||
385 |