Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 18 | class ForgeCommandTest extends BaseCommandTestCase |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Data provider for show command. |
||
| 22 | * |
||
| 23 | * @return array |
||
| 24 | */ |
||
| 25 | public function showTestDataProvider() : array |
||
| 26 | { |
||
| 27 | return [ |
||
| 28 | 'forge:show 23456' => ['23456'], |
||
| 29 | 'forge:show http://forge.typo3.org/issues/23456/' => ['http://forge.typo3.org/issues/23456/'], |
||
| 30 | 'forge:show https://forge.typo3.org/issues/23456/' => ['https://forge.typo3.org/issues/23456/'], |
||
| 31 | 'forge:show http://forge.typo3.org/issues/23456' => ['http://forge.typo3.org/issues/23456'], |
||
| 32 | 'forge:show https://forge.typo3.org/issues/23456' => ['https://forge.typo3.org/issues/23456'], |
||
| 33 | ]; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @test |
||
| 38 | */ |
||
| 39 | public function processShowReturnsCorrectResponseForNoOptions() |
||
| 40 | { |
||
| 41 | $this->initCommandWithPayload(ForgeCommand::class, [ |
||
| 42 | 'user' => 'U54321', |
||
| 43 | 'text' => 'forge:show', |
||
| 44 | ]); |
||
| 45 | $result = $this->command->process(); |
||
| 46 | static::assertEquals('hey, I need an issue number!', $result); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @test |
||
| 51 | */ |
||
| 52 | public function processShowReturnsCorrectResponseForInvalidIssueNumber() |
||
| 53 | { |
||
| 54 | $this->initCommandWithPayload(ForgeCommand::class, [ |
||
| 55 | 'user' => 'U54321', |
||
| 56 | 'text' => 'forge:show asdasd', |
||
| 57 | ]); |
||
| 58 | $result = $this->command->process(); |
||
| 59 | static::assertEquals('hey, I need an issue number!', $result); |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @test |
||
| 64 | */ |
||
| 65 | public function processShowReturnsCorrectResponseForUnknownIssueNumber() |
||
| 66 | { |
||
| 67 | $this->initCommandWithPayload(ForgeCommand::class, [ |
||
| 68 | 'user' => 'U54321', |
||
| 69 | 'text' => 'forge:show 99999', |
||
| 70 | ]); |
||
| 71 | $result = $this->command->process(); |
||
| 72 | static::assertEquals('Sorry not found!', $result); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @test |
||
| 77 | * @dataProvider showTestDataProvider |
||
| 78 | * |
||
| 79 | * @param string $issueNumber |
||
| 80 | */ |
||
| 81 | public function processShowReturnsCorrectResponseForValidIssueNumbers($issueNumber) |
||
| 82 | { |
||
| 83 | $this->initCommandWithPayload(ForgeCommand::class, [ |
||
| 84 | 'user' => 'U54321', |
||
| 85 | 'text' => 'forge:show ' . $issueNumber, |
||
| 86 | ]); |
||
| 87 | $result = $this->command->process(); |
||
| 88 | |||
| 89 | static::assertStringStartsWith('*[Bug] Cannot edit media links with IE8* by _Michael Gotzen_', $result); |
||
| 90 | } |
||
| 91 | } |
||
| 92 |