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 |
||
| 13 | class ChannelRepositoryTest extends WebTestCase |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var ChannelRepository |
||
| 17 | */ |
||
| 18 | protected $repository; |
||
| 19 | |||
| 20 | View Code Duplication | protected function setUp() |
|
| 31 | |||
| 32 | public function testRepositoryIsRegistered() |
||
| 36 | |||
| 37 | public function testGetLastStatusForConnectorWorks() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @dataProvider getRunningSyncJobsCountDataProvider |
||
| 61 | * |
||
| 62 | * @param string $command |
||
| 63 | * @param int $expectedCount |
||
| 64 | * @param null|string $integration |
||
| 65 | */ |
||
| 66 | View Code Duplication | public function testGetRunningSyncJobsCount($command, $expectedCount, $integration = null) |
|
| 67 | { |
||
| 68 | $integration = $integration ? $this->getReference($integration)->getId() : null; |
||
| 69 | $actual = $this->repository->getRunningSyncJobsCount($command, $integration); |
||
| 70 | |||
| 71 | $this->assertEquals($expectedCount, $actual); |
||
| 72 | } |
||
| 73 | |||
| 74 | View Code Duplication | public function getRunningSyncJobsCountDataProvider() |
|
| 75 | { |
||
| 76 | return [ |
||
| 77 | [ |
||
| 78 | 'command' => 'first_test_command', |
||
| 79 | 'expectedCount' => 2 |
||
| 80 | ], |
||
| 81 | [ |
||
| 82 | 'command' => 'second_test_command', |
||
| 83 | 'expectedCount' => 1 |
||
| 84 | ], |
||
| 85 | [ |
||
| 86 | 'command' => 'third_test_command', |
||
| 87 | 'expectedCount' => 2, |
||
| 88 | 'integration' => 'oro_integration:foo_integration', |
||
| 89 | ] |
||
| 90 | ]; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @dataProvider getExistingSyncJobsCountDataProvider |
||
| 95 | * |
||
| 96 | * @param string $command |
||
| 97 | * @param int $expectedCount |
||
| 98 | * @param null|string $integration |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function testGetExistingSyncJobsCount($command, $expectedCount, $integration = null) |
|
| 107 | |||
| 108 | View Code Duplication | public function getExistingSyncJobsCountDataProvider() |
|
| 126 | } |
||
| 127 |