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 |
||
| 14 | class CliTest extends BaseTestRunner |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Tests Cli::execute |
||
| 18 | */ |
||
| 19 | public function testExecuteSuccess() |
||
| 20 | { |
||
| 21 | $config = $this->getConfigMock(); |
||
| 22 | $io = $this->getIOMock(); |
||
| 23 | $repo = $this->getRepositoryMock(); |
||
| 24 | $action = $this->getActionConfigMock(); |
||
| 25 | |||
| 26 | $cmd = HMU_PATH_FILES . '/bin/success'; |
||
| 27 | |||
| 28 | $io->expects($this->once())->method('write'); |
||
| 29 | $action->expects($this->once())->method('getAction')->willReturn($cmd); |
||
| 30 | |||
| 31 | $cli = new Cli(); |
||
| 32 | $cli->execute($config, $io, $repo, $action); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Tests Cli::execute |
||
| 37 | * |
||
| 38 | * @expectedException \Exception |
||
| 39 | */ |
||
| 40 | public function testExecuteFailure() |
||
| 41 | { |
||
| 42 | $config = $this->getConfigMock(); |
||
| 43 | $io = $this->getIOMock(); |
||
| 44 | $repo = $this->getRepositoryMock(); |
||
| 45 | $action = $this->getActionConfigMock(); |
||
| 46 | |||
| 47 | $cmd = HMU_PATH_FILES . '/bin/failure'; |
||
| 48 | |||
| 49 | $action->expects($this->once())->method('getAction')->willReturn($cmd); |
||
| 50 | |||
| 51 | $cli = new Cli(); |
||
| 52 | $cli->execute($config, $io, $repo, $action); |
||
| 53 | } |
||
| 54 | } |
||
| 55 |