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 |
||
38 | class FlexiBeeROTest extends \Test\Ease\BrickTest |
||
|
|||
39 | { |
||
40 | /** |
||
41 | * @var FlexiBeeRO |
||
42 | */ |
||
43 | protected $object; |
||
44 | |||
45 | /** |
||
46 | * Sets up the fixture, for example, opens a network connection. |
||
47 | * This method is called before a test is executed. |
||
48 | * @covers FlexiPeeHP\FlexiBeeRO::__construct |
||
49 | */ |
||
50 | protected function setUp() |
||
58 | |||
59 | /** |
||
60 | * Tears down the fixture, for example, closes a network connection. |
||
61 | * This method is called after a test is executed. |
||
62 | */ |
||
63 | protected function tearDown() |
||
67 | |||
68 | /** |
||
69 | * @covers FlexiPeeHP\FlexiBeeRO::curlInit |
||
70 | */ |
||
71 | public function testCurlInit() |
||
76 | |||
77 | /** |
||
78 | * @covers FlexiPeeHP\FlexiBeeRO::processInit |
||
79 | */ |
||
80 | public function testProcessInit() |
||
91 | |||
92 | /** |
||
93 | * @covers FlexiPeeHP\FlexiBeeRO::setEvidence |
||
94 | */ |
||
95 | public function testSetEvidence() |
||
100 | |||
101 | /** |
||
102 | * @covers FlexiPeeHP\FlexiBeeRO::object2array |
||
103 | */ |
||
104 | public function testObject2array() |
||
114 | |||
115 | /** |
||
116 | * @covers FlexiPeeHP\FlexiBeeRO::objectToID |
||
117 | */ |
||
118 | public function testObjectToID() |
||
128 | |||
129 | /** |
||
130 | * @covers FlexiPeeHP\FlexiBeeRO::performRequest |
||
131 | */ |
||
132 | public function testPerformRequest() |
||
158 | |||
159 | /** |
||
160 | * @covers FlexiPeeHP\FlexiBeeRO::getLastInsertedId |
||
161 | * @depends testInsertToFlexiBee |
||
162 | */ |
||
163 | public function testGetLastInsertedId() |
||
167 | |||
168 | /** |
||
169 | * @covers FlexiPeeHP\FlexiBeeRO::xml2array |
||
170 | */ |
||
171 | public function testXml2array() |
||
188 | |||
189 | /** |
||
190 | * @covers FlexiPeeHP\FlexiBeeRO::disconnect |
||
191 | * |
||
192 | * @depends testPerformRequest |
||
193 | * @depends testLoadFlexiData |
||
194 | * @depends testGetFlexiRow |
||
195 | * @depends testGetFlexiData |
||
196 | * @depends testLoadFromFlexiBee |
||
197 | * @depends testInsertToFlexiBee |
||
198 | * @depends testIdExists |
||
199 | * @depends testRecordExists |
||
200 | * @depends testGetColumnsFromFlexibee |
||
201 | * @depends testSearchString |
||
202 | */ |
||
203 | public function testDisconnect() |
||
208 | |||
209 | /** |
||
210 | * @covers FlexiPeeHP\FlexiBeeRO::__destruct |
||
211 | * @depends testDisconnect |
||
212 | */ |
||
213 | public function test__destruct() |
||
217 | |||
218 | /** |
||
219 | * @covers FlexiPeeHP\FlexiBeeRO::loadFlexiData |
||
220 | * @todo Implement testLoadFlexiData(). |
||
221 | */ |
||
222 | public function testLoadFlexiData() |
||
229 | |||
230 | /** |
||
231 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiRow |
||
232 | */ |
||
233 | public function testGetFlexiRow() |
||
238 | |||
239 | /** |
||
240 | * @covers FlexiPeeHP\FlexiBeeRO::getFlexiData |
||
241 | */ |
||
242 | public function testGetFlexiData() |
||
261 | |||
262 | /** |
||
263 | * @covers FlexiPeeHP\FlexiBeeRO::loadFromFlexiBee |
||
264 | */ |
||
265 | public function testLoadFromFlexiBee() |
||
270 | |||
271 | /** |
||
272 | * @covers FlexiPeeHP\FlexiBeeRO::jsonizeData |
||
273 | */ |
||
274 | public function testJsonizeData() |
||
279 | |||
280 | /** |
||
281 | * @covers FlexiPeeHP\FlexiBeeRO::idExists |
||
282 | * @todo Implement testIdExists(). |
||
283 | */ |
||
284 | public function testIdExists() |
||
291 | |||
292 | /** |
||
293 | * @covers FlexiPeeHP\FlexiBeeRO::recordExists |
||
294 | */ |
||
295 | public function testRecordExists() |
||
300 | |||
301 | /** |
||
302 | * @covers FlexiPeeHP\FlexiBeeRO::getColumnsFromFlexibee |
||
303 | * @todo Implement testGetColumnsFromFlexibee(). |
||
304 | */ |
||
305 | public function testGetColumnsFromFlexibee() |
||
312 | |||
313 | /** |
||
314 | * @covers FlexiPeeHP\FlexiBeeRO::getKod |
||
315 | */ |
||
316 | public function testGetKod() |
||
343 | |||
344 | /** |
||
345 | * @covers FlexiPeeHP\FlexiBeeRO::searchString |
||
346 | * @todo Implement testSearchString(). |
||
347 | */ |
||
348 | public function testSearchString() |
||
355 | |||
356 | /** |
||
357 | * @covers FlexiPeeHP\FlexiBeeRO::logResult |
||
358 | */ |
||
359 | public function testLogResult() |
||
379 | |||
380 | /** |
||
381 | * @covers FlexiPeeHP\FlexiBeeRO::flexiUrl |
||
382 | */ |
||
383 | public function testFlexiUrl() |
||
394 | |||
395 | /** |
||
396 | * @covers FlexiPeeHP\FlexiBeeRO::__toString |
||
397 | * @expectedException \Exception |
||
398 | */ |
||
399 | public function test__toString() |
||
413 | |||
414 | /** |
||
415 | * @covers FlexiPeeHP\FlexiBeeRO::draw |
||
416 | */ |
||
417 | public function testDraw() |
||
422 | } |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.