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 PHPTest extends BaseTestRunner |
||
19 | { |
||
20 | /** |
||
21 | * Tests PHP::execute |
||
22 | */ |
||
23 | public function testExecuteSuccess() |
||
24 | { |
||
25 | $config = $this->getConfigMock(); |
||
26 | $io = $this->getIOMock(); |
||
27 | $repo = $this->getRepositoryMock(); |
||
28 | $action = $this->getActionConfigMock(); |
||
29 | |||
30 | $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyPHPSuccess'; |
||
31 | |||
32 | $action->expects($this->once())->method('getAction')->willReturn($class); |
||
33 | |||
34 | $php = new PHP(); |
||
35 | $php->execute($config, $io, $repo, $action); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Tests PHP::execute |
||
40 | * |
||
41 | * @expectedException \Exception |
||
42 | */ |
||
43 | public function testExecuteFailure() |
||
44 | { |
||
45 | $config = $this->getConfigMock(); |
||
46 | $io = $this->getIOMock(); |
||
47 | $repo = $this->getRepositoryMock(); |
||
48 | $action = $this->getActionConfigMock(); |
||
49 | |||
50 | $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyPHPFailure'; |
||
51 | |||
52 | $action->expects($this->once())->method('getAction')->willReturn($class); |
||
53 | |||
54 | $php = new PHP(); |
||
55 | $php->execute($config, $io, $repo, $action); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Tests PHP::execute |
||
60 | * |
||
61 | * @expectedException \Exception |
||
62 | */ |
||
63 | public function testExecuteError() |
||
64 | { |
||
65 | $config = $this->getConfigMock(); |
||
66 | $io = $this->getIOMock(); |
||
67 | $repo = $this->getRepositoryMock(); |
||
68 | $action = $this->getActionConfigMock(); |
||
69 | |||
70 | $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyPHPError'; |
||
71 | |||
72 | $action->expects($this->once())->method('getAction')->willReturn($class); |
||
73 | |||
74 | $php = new PHP(); |
||
75 | $php->execute($config, $io, $repo, $action); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Tests PHP::execute |
||
80 | * |
||
81 | * @expectedException \Exception |
||
82 | */ |
||
83 | public function testExecuteNoAction() |
||
84 | { |
||
85 | $config = $this->getConfigMock(); |
||
86 | $io = $this->getIOMock(); |
||
87 | $repo = $this->getRepositoryMock(); |
||
88 | $action = $this->getActionConfigMock(); |
||
89 | |||
90 | $class = '\\sebastianfeldmann\\CaptainHook\\Runner\\Action\\DummyNoAction'; |
||
91 | |||
92 | $action->expects($this->once())->method('getAction')->willReturn($class); |
||
93 | |||
94 | $php = new PHP(); |
||
95 | $php->execute($config, $io, $repo, $action); |
||
96 | } |
||
97 | } |
||
98 | |||
160 |