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 |
||
| 22 | class SlugConverterTest extends TestCase |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Test for the __construct() method. |
||
| 26 | * |
||
| 27 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter::__construct |
||
| 28 | */ |
||
| 29 | public function testConstructor() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Test for the convert() method. |
||
| 48 | * |
||
| 49 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter::convert |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function testConvert() |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Test for the convert() method. |
||
| 78 | * |
||
| 79 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter::convert |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function testConvertWithDefaultTextFallback() |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Test for the convert() method. |
||
| 108 | * |
||
| 109 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter::convert |
||
| 110 | */ |
||
| 111 | View Code Duplication | public function testConvertWithGivenTransformation() |
|
| 135 | |||
| 136 | public function providerForTestGetUniqueCounterValue() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Test for the getUniqueCounterValue() method. |
||
| 148 | * |
||
| 149 | * @dataProvider providerForTestGetUniqueCounterValue |
||
| 150 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter::getUniqueCounterValue |
||
| 151 | */ |
||
| 152 | public function testGetUniqueCounterValue($text, $isRootLevel, $returnValue) |
||
| 161 | |||
| 162 | public function cleanupTextData() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Test for the cleanupText() method. |
||
| 185 | * |
||
| 186 | * @dataProvider cleanupTextData |
||
| 187 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter::cleanupText |
||
| 188 | */ |
||
| 189 | public function testCleanupText($text, $method, $expected) |
||
| 204 | |||
| 205 | public function convertData() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Test for the convert() method. |
||
| 231 | * |
||
| 232 | * @dataProvider convertData |
||
| 233 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter::convert |
||
| 234 | * @depends testCleanupText |
||
| 235 | */ |
||
| 236 | public function testConvertNoMocking($text, $defaultText, $transformation, $expected) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @var array |
||
| 259 | */ |
||
| 260 | protected $configuration = array( |
||
| 261 | 'transformation' => 'testTransformation1', |
||
| 262 | 'transformationGroups' => array( |
||
| 263 | 'testTransformation1' => array( |
||
| 264 | 'commands' => array( |
||
| 265 | 'test_command1', |
||
| 266 | ), |
||
| 267 | 'cleanupMethod' => 'test_cleanup1', |
||
| 268 | ), |
||
| 269 | 'testTransformation2' => array( |
||
| 270 | 'commands' => array( |
||
| 271 | 'test_command2', |
||
| 272 | ), |
||
| 273 | 'cleanupMethod' => 'test_cleanup2', |
||
| 274 | ), |
||
| 275 | ), |
||
| 276 | 'reservedNames' => array( |
||
| 277 | 'reserved', |
||
| 278 | ), |
||
| 279 | ); |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter |
||
| 283 | */ |
||
| 284 | protected $slugConverter; |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 288 | */ |
||
| 289 | protected $slugConverterMock; |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 293 | */ |
||
| 294 | protected $transformationProcessorMock; |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter |
||
| 298 | */ |
||
| 299 | protected function getMockedSlugConverter() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @param array $methods |
||
| 313 | * |
||
| 314 | * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter|\PHPUnit_Framework_MockObject_MockObject |
||
| 315 | */ |
||
| 316 | protected function getSlugConverterMock(array $methods = array()) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @return \PHPUnit_Framework_MockObject_MockObject |
||
| 334 | */ |
||
| 335 | protected function getTransformationProcessorMock() |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Returns the test suite with all tests declared in this class. |
||
| 354 | * |
||
| 355 | * @return \PHPUnit_Framework_TestSuite |
||
| 356 | */ |
||
| 357 | public static function suite() |
||
| 361 | } |
||
| 362 |