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 |
||
10 | class ComposeManagerTest extends PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | public function setUp() |
||
18 | |||
19 | /** |
||
20 | * Test simple start without error |
||
21 | */ |
||
22 | public function testStart() |
||
27 | |||
28 | /** |
||
29 | * Test start success with one compose file |
||
30 | */ |
||
31 | public function testStartWithOneComposeFileSpecified() |
||
36 | |||
37 | /** |
||
38 | * Test start success with two compose files |
||
39 | */ |
||
40 | public function testStartWithTwoComposeFilesSpecified() |
||
45 | |||
46 | /** |
||
47 | * Test start with project option |
||
48 | */ |
||
49 | public function testStartWithprojectOption() |
||
59 | |||
60 | /** |
||
61 | * Test start with project and networking option |
||
62 | */ |
||
63 | public function testStartWithprojectAndNetworkingOption() |
||
71 | |||
72 | /** |
||
73 | * Test start with project, networking and network driver option |
||
74 | */ |
||
75 | View Code Duplication | public function testStartWithprojectAndNetworkingWithDriverOption() |
|
83 | |||
84 | /** |
||
85 | * Test start with ComposeFileNotFoundException |
||
86 | * |
||
87 | * @expectedException \Exception |
||
88 | */ |
||
89 | public function testStartThrowExceptionForDriver() |
||
95 | |||
96 | /** |
||
97 | * Test start with ComposeFileNotFoundException |
||
98 | * |
||
99 | * @expectedException \DockerCompose\Exception\ComposeFileNotFoundException |
||
100 | */ |
||
101 | View Code Duplication | public function testStartThrowComposeFileNotFound() |
|
108 | |||
109 | /** |
||
110 | * Test start with DockerHostConnexionErrorException |
||
111 | * |
||
112 | * @expectedException \DockerCompose\Exception\DockerHostConnexionErrorException |
||
113 | */ |
||
114 | View Code Duplication | public function testStartThrowDockerHostConnexionErrorException() |
|
121 | |||
122 | /** |
||
123 | * Test start with DockerInstallationMissingException |
||
124 | * |
||
125 | * @expectedException \DockerCompose\Exception\DockerInstallationMissingException |
||
126 | */ |
||
127 | public function testStartThrowDockerInstallationMissingException() |
||
132 | |||
133 | /** |
||
134 | * Test start with DockerInstallationMissingException |
||
135 | * |
||
136 | * @expectedException \Exception |
||
137 | */ |
||
138 | public function testStartThrowUnknownException() |
||
143 | |||
144 | /** |
||
145 | * Test stop whithout error |
||
146 | */ |
||
147 | public function testStop() |
||
152 | |||
153 | /** |
||
154 | * Test stop success with one compose file |
||
155 | */ |
||
156 | public function testStopWithOneComposeFileSpecified() |
||
162 | |||
163 | /** |
||
164 | * Test stop success with two compose files |
||
165 | */ |
||
166 | public function testStopWithTwoComposeFilesSpecified() |
||
172 | |||
173 | /** |
||
174 | * Test stop with ComposeFileNotFoundException |
||
175 | * |
||
176 | * @expectedException \DockerCompose\Exception\ComposeFileNotFoundException |
||
177 | */ |
||
178 | View Code Duplication | public function testStopThrowComposeFileNotFound() |
|
185 | |||
186 | /** |
||
187 | * Test stop with DockerHostConnexionErrorException |
||
188 | * |
||
189 | * @expectedException \DockerCompose\Exception\DockerHostConnexionErrorException |
||
190 | */ |
||
191 | View Code Duplication | public function testStopThrowDockerHostConnexionErrorException() |
|
198 | |||
199 | /** |
||
200 | * Test stop with DockerInstallationMissingException |
||
201 | * |
||
202 | * @expectedException \DockerCompose\Exception\DockerInstallationMissingException |
||
203 | */ |
||
204 | public function testStopThrowDockerInstallationMissingException() |
||
209 | |||
210 | /** |
||
211 | * Test remove whithout error |
||
212 | */ |
||
213 | public function testRemove() |
||
218 | |||
219 | /** |
||
220 | * Test remove force |
||
221 | */ |
||
222 | public function testRemoveForce() |
||
227 | |||
228 | /** |
||
229 | * Test remove volumes |
||
230 | */ |
||
231 | public function testRemoveVolumes() |
||
236 | |||
237 | /** |
||
238 | * Test remove force and volumes |
||
239 | */ |
||
240 | public function testRemoveForceAndVolumes() |
||
245 | |||
246 | /** |
||
247 | * Test remove success with one compose file |
||
248 | */ |
||
249 | public function testRemoveWithOneComposeFileSpecified() |
||
255 | |||
256 | /** |
||
257 | * Test remove success with two compose files |
||
258 | */ |
||
259 | public function testRemoveWithTwoComposeFilesSpecified() |
||
265 | |||
266 | /** |
||
267 | * Test remove with ComposeFileNotFoundException |
||
268 | * |
||
269 | * @expectedException \DockerCompose\Exception\ComposeFileNotFoundException |
||
270 | */ |
||
271 | View Code Duplication | public function testRemoveThrowComposeFileNotFound() |
|
278 | |||
279 | /** |
||
280 | * Test remove with DockerHostConnexionErrorException |
||
281 | * |
||
282 | * @expectedException \DockerCompose\Exception\DockerHostConnexionErrorException |
||
283 | */ |
||
284 | View Code Duplication | public function testRemoveThrowDockerHostConnexionErrorException() |
|
291 | |||
292 | /** |
||
293 | * Test remove with DockerInstallationMissingException |
||
294 | * |
||
295 | * @expectedException \DockerCompose\Exception\DockerInstallationMissingException |
||
296 | */ |
||
297 | public function testRemoveThrowDockerInstallationMissingException() |
||
302 | |||
303 | /** |
||
304 | * Test run |
||
305 | */ |
||
306 | public function testrun() |
||
311 | |||
312 | /** |
||
313 | * Test run |
||
314 | * @expectedException \DockerCompose\Exception\NoSuchServiceException |
||
315 | */ |
||
316 | public function testrunThrowNoSuchServiceException() |
||
321 | |||
322 | /** |
||
323 | * Test run with project, networking and network driver option |
||
324 | */ |
||
325 | View Code Duplication | public function testRuntWithprojectAndNetworkingWithDriverOption() |
|
333 | |||
334 | /** |
||
335 | * Test simple build without error |
||
336 | */ |
||
337 | public function testBuild() |
||
342 | |||
343 | /** |
||
344 | * Test build success with one compose file |
||
345 | */ |
||
346 | public function testBuildWithOneComposeFileSpecified() |
||
351 | |||
352 | /** |
||
353 | * Test build success with two compose files |
||
354 | */ |
||
355 | public function testBuildWithTwoComposeFilesSpecified() |
||
360 | |||
361 | /** |
||
362 | * Test simple build without pull |
||
363 | */ |
||
364 | public function testBuildWithoutPull() |
||
369 | |||
370 | /** |
||
371 | * Test simple build with --force-rm |
||
372 | */ |
||
373 | public function testBuildWithForceRm() |
||
378 | |||
379 | /** |
||
380 | * Test simple build with --no-cache |
||
381 | */ |
||
382 | public function testBuildWithNoCache() |
||
387 | |||
388 | /** |
||
389 | * Test simple build with --pull --force-rm --no-cache |
||
390 | */ |
||
391 | public function testBuildWithPullAndForceRmAndNoCache() |
||
396 | } |
||
397 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.