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 |
||
| 8 | class DateIntervalTest extends \Doctrine\Tests\DbalTestCase |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var MockPlatform |
||
| 12 | */ |
||
| 13 | private $platform; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var \Doctrine\DBAL\Types\DateIntervalType |
||
| 17 | */ |
||
| 18 | private $type; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * {@inheritDoc} |
||
| 22 | */ |
||
| 23 | protected function setUp() |
||
| 30 | |||
| 31 | View Code Duplication | public function testDateIntervalConvertsToDatabaseValue() |
|
| 40 | |||
| 41 | public function testDateIntervalConvertsToPHPValue() |
||
| 47 | |||
| 48 | View Code Duplication | public function testNegativeDateIntervalConvertsToDatabaseValue() |
|
| 49 | { |
||
| 50 | $interval = new \DateInterval('P2Y1DT1H2M3S'); |
||
| 51 | $interval->invert = 1; |
||
| 52 | |||
| 53 | $expected = '-P02Y00M01DT01H02M03S'; |
||
| 54 | $actual = $this->type->convertToDatabaseValue($interval, $this->platform); |
||
| 55 | |||
| 56 | $this->assertEquals($expected, $actual); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function testNegativeDateIntervalConvertsToPHPValue() |
||
| 60 | { |
||
| 61 | $interval = $this->type->convertToPHPValue('-P02Y00M01DT01H02M03S', $this->platform); |
||
| 62 | $this->assertInstanceOf('DateInterval', $interval); |
||
| 63 | $this->assertEquals('-P02Y00M01DT01H02M03S', $interval->format('%RP%YY%MM%DDT%HH%IM%SS')); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function testInvalidDateIntervalFormatConversion() |
||
| 71 | |||
| 72 | public function testDateIntervalNullConversion() |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @group DBAL-1288 |
||
| 79 | */ |
||
| 80 | public function testRequiresSQLCommentHint() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @dataProvider invalidPHPValuesProvider |
||
| 87 | * |
||
| 88 | * @param mixed $value |
||
| 89 | */ |
||
| 90 | public function testInvalidTypeConversionToDatabaseValue($value) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @return mixed[][] |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function invalidPHPValuesProvider() |
|
| 119 | } |
||
| 120 |