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