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 |
||
| 8 | class FacadeTest extends \Codeception\Test\Unit |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var \Nexus\CustomCommand\CustomCommandFacade |
||
| 12 | */ |
||
| 13 | private $facade; |
||
| 14 | |||
| 15 | protected function _before() |
||
| 16 | { |
||
| 17 | $this->facade = Locator::getInstance()->customCommand()->facade(); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @group Nexus |
||
| 22 | * @group CustomCommand |
||
| 23 | * @group Facade |
||
| 24 | * @group Integration |
||
| 25 | */ |
||
| 26 | public function testHydrateCommandsRecusive() |
||
| 27 | { |
||
| 28 | $commands = $this->facade->hydrateCommands([], __DIR__ . '/test', true); |
||
| 29 | |||
| 30 | $this->assertCount(2, $commands); |
||
| 31 | |||
| 32 | $this->assertInstanceOf( |
||
| 33 | 'Nexus\\CustomCommand\\Command\\TestCommand', |
||
| 34 | $commands[0] |
||
| 35 | ); |
||
| 36 | $this->assertInstanceOf( |
||
| 37 | 'Nexus\\CustomCommand\\Command\\TestRecursiveCommand', |
||
| 38 | $commands[1] |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @group Nexus |
||
| 44 | * @group CustomCommand |
||
| 45 | * @group Facade |
||
| 46 | * @group Integration |
||
| 47 | */ |
||
| 48 | public function testHydrateCommandsNotRecusive() |
||
| 49 | { |
||
| 50 | $commands = $this->facade->hydrateCommands([], __DIR__ . '/test', false); |
||
| 51 | |||
| 52 | $this->assertCount(1, $commands); |
||
| 53 | |||
| 54 | $this->assertInstanceOf( |
||
| 55 | 'Nexus\\CustomCommand\\Command\\TestCommand', |
||
| 56 | $commands[0] |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @group Nexus |
||
| 62 | * @group CustomCommand |
||
| 63 | * @group Facade |
||
| 64 | * @group Integration |
||
| 65 | */ |
||
| 66 | public function testHydrateCommandsWithNonExistingDirectory() |
||
| 67 | { |
||
| 68 | $commands = $this->facade->hydrateCommands([], __DIR__ . '/notExisting', false); |
||
| 69 | |||
| 70 | $this->assertCount(0, $commands); |
||
| 71 | } |
||
| 72 | } |