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 |
||
12 | class InstallerTest extends BaseTestRunner |
||
13 | { |
||
14 | /** |
||
15 | * Tests Installer::setHook |
||
16 | * |
||
17 | * @expectedException \Exception |
||
18 | */ |
||
19 | public function testSetHookInvalid() |
||
20 | { |
||
21 | $io = $this->getIOMock(); |
||
22 | $config = $this->getConfigMock(); |
||
23 | $repo = $this->getRepositoryMock(); |
||
24 | $runner = new Installer($io, $config, $repo); |
||
25 | $runner->setHook('iDoNotExist'); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Tests Installer::installHook |
||
30 | */ |
||
31 | public function testInstallHook() |
||
32 | { |
||
33 | $io = $this->getIOMock(); |
||
34 | $config = $this->getConfigMock(); |
||
35 | $repo = $this->getRepositoryMock(); |
||
36 | $runner = new Installer($io, $config, $repo); |
||
37 | $io->expects($this->once())->method('ask')->willReturn('no'); |
||
38 | $runner->installHook('pre-push', true); |
||
39 | } |
||
40 | |||
41 | |||
42 | /** |
||
43 | * Tests Installer::installHook |
||
44 | */ |
||
45 | public function testWriteHookFile() |
||
46 | { |
||
47 | $io = $this->getIOMock(); |
||
48 | $config = $this->getConfigMock(); |
||
49 | $repo = $this->getRepositoryMock(); |
||
50 | $runner = new Installer($io, $config, $repo); |
||
51 | $repo->expects($this->once())->method('hookExists')->willReturn(true); |
||
52 | $io->expects($this->once())->method('ask')->willReturn('no'); |
||
53 | $runner->writeHookFile('pre-push', true); |
||
54 | } |
||
55 | } |
||
56 |