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 |
||
| 23 | class WkbTest extends TestCase |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var Wkb |
||
| 27 | */ |
||
| 28 | private $dumper; |
||
| 29 | |||
| 30 | public function setUp() |
||
| 31 | { |
||
| 32 | $this->dumper = new Wkb(); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function testDump() |
||
| 36 | { |
||
| 37 | $address = Address::createFromArray([]); |
||
| 38 | $expected = pack('H*', '010100000000000000000000000000000000000000'); |
||
| 39 | $result = $this->dumper->dump($address); |
||
| 40 | |||
| 41 | $this->assertTrue(is_string($result)); |
||
| 42 | $this->assertEquals($expected, $result); |
||
| 43 | } |
||
| 44 | |||
| 45 | public function testDumpWithData() |
||
| 46 | { |
||
| 47 | $address = Address::createFromArray([ |
||
| 48 | 'latitude' => 48.8631507, |
||
| 49 | 'longitude' => 2.3889114, |
||
| 50 | ]); |
||
| 51 | $expected = pack('H*', '0101000000255580947D1C03407F02DEB87B6E4840'); |
||
| 52 | |||
| 53 | $result = $this->dumper->dump($address); |
||
| 54 | |||
| 55 | $this->assertTrue(is_string($result)); |
||
| 56 | $this->assertEquals($expected, $result); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |