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 |
||
| 3 | class DMSDocumentCartExtensionTest extends SapphireTest |
||
|
|
|||
| 4 | { |
||
| 5 | protected static $fixture_file = 'DMSDocumentCartExtensionTest.yml'; |
||
| 6 | |||
| 7 | protected $requiredExtensions = array( |
||
| 8 | 'DMSDocument' => array('DMSDocumentCartExtension') |
||
| 9 | ); |
||
| 10 | |||
| 11 | public function testMaximumCartQuantity() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The CSS classes are required for the CMS Javascript to work, assert that they are correct |
||
| 30 | */ |
||
| 31 | View Code Duplication | public function testCmsFieldsHaveRequiredCssClasses() |
|
| 43 | |||
| 44 | /** |
||
| 45 | * Ensure that validation messages can be retrieved once, cleared, then not again |
||
| 46 | */ |
||
| 47 | public function testGetValidationResult() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Test that print request count is shown in the document's summary |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function testPrintRequestCountIsShownInDocumentSummary() |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @expectedException DMSDocumentCartException |
||
| 75 | * @expectedExceptionMessage peanut is not accepted for this method. |
||
| 76 | */ |
||
| 77 | public function testGetActionLinkThrowsExceptionOnInvalidAction() |
||
| 81 | } |
||
| 82 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.