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 ManagerTest extends TestCase |
||
19 | { |
||
20 | /** |
||
21 | * @covers \EasyDictionary\Manager |
||
22 | */ |
||
23 | public function testClassExistence() |
||
27 | |||
28 | /** |
||
29 | * @covers ::__construct |
||
30 | * @covers ::setConfig |
||
31 | * @covers ::getConfig |
||
32 | */ |
||
33 | public function testSetConfigFromConstructor() |
||
40 | |||
41 | /** |
||
42 | * @covers ::__construct |
||
43 | * @covers ::getConfig |
||
44 | * @covers ::get |
||
45 | * |
||
46 | * @expectedException \EasyDictionary\Exception\RuntimeException |
||
47 | * @expectedExceptionMessage Config not found |
||
48 | */ |
||
49 | public function testGetDictionaryWithoutConfig() |
||
54 | |||
55 | /** |
||
56 | * @covers ::__construct |
||
57 | * @covers ::setConfig |
||
58 | * @covers ::getConfig |
||
59 | * @covers ::get |
||
60 | * |
||
61 | * @expectedException \EasyDictionary\Exception\RuntimeException |
||
62 | * @expectedExceptionMessage Dictionary with key "test" not found |
||
63 | */ |
||
64 | public function testGetANonExistentDictionary() |
||
70 | |||
71 | /** |
||
72 | * @covers ::__construct |
||
73 | * @covers ::add |
||
74 | * @covers ::get |
||
75 | */ |
||
76 | View Code Duplication | public function testAddNewDictionary() |
|
87 | |||
88 | /** |
||
89 | * @covers ::__construct |
||
90 | * @covers ::add |
||
91 | * @covers ::get |
||
92 | * |
||
93 | * @expectedException \EasyDictionary\Exception\RuntimeException |
||
94 | * @expectedExceptionMessage The dictionary with key "test" already exists |
||
95 | */ |
||
96 | View Code Duplication | public function testAddDuplicatedDictionary() |
|
108 | |||
109 | /** |
||
110 | * @covers ::get |
||
111 | * @covers ::add |
||
112 | * @covers ::create |
||
113 | */ |
||
114 | public function testCreateSimpleDictionary() |
||
152 | |||
153 | /** |
||
154 | * @covers \EasyDictionary\AbstractDictionary |
||
155 | * @covers \EasyDictionary\DataProvider\Simple |
||
156 | * @covers ::<public> |
||
157 | * @covers ::create |
||
158 | * @covers ::createDataProvider |
||
159 | */ |
||
160 | public function testCreateRealDictionary() |
||
179 | |||
180 | /** |
||
181 | * @covers ::<public> |
||
182 | * @covers ::create |
||
183 | * @covers ::createDataProvider |
||
184 | * @expectedException \EasyDictionary\Exception\InvalidConfigurationException |
||
185 | * @expectedExceptionMessage Class "/bad/dataprovider/class" not found |
||
186 | */ |
||
187 | public function testGetExceptionOfUndefinedDataProviderClass() |
||
202 | |||
203 | /** |
||
204 | * @covers ::<public> |
||
205 | * @covers ::create |
||
206 | * @covers ::createDataProvider |
||
207 | * @expectedException \EasyDictionary\Exception\InvalidConfigurationException |
||
208 | * @expectedExceptionMessage Class "stdClass" is not implement required interface |
||
209 | */ |
||
210 | View Code Duplication | public function testGetExceptionOfBadDataProviderClass() |
|
225 | |||
226 | /** |
||
227 | * @covers \EasyDictionary\DataProvider\Simple |
||
228 | * @covers ::<public> |
||
229 | * @covers ::create |
||
230 | * @covers ::createDataProvider |
||
231 | * @expectedException \EasyDictionary\Exception\InvalidConfigurationException |
||
232 | * @expectedExceptionMessage Class "/bad/dictionary/class" not found |
||
233 | */ |
||
234 | View Code Duplication | public function testGetExceptionOfUndefinedDictionaryClass() |
|
250 | |||
251 | /** |
||
252 | * @covers \EasyDictionary\DataProvider\Simple |
||
253 | * @covers ::<public> |
||
254 | * @covers ::create |
||
255 | * @covers ::createDataProvider |
||
256 | * @expectedException \EasyDictionary\Exception\InvalidConfigurationException |
||
257 | * @expectedExceptionMessage Class "stdClass" not found |
||
258 | */ |
||
259 | View Code Duplication | public function testGetExceptionOfBadDictionaryClass() |
|
275 | } |
||
276 |