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 |
||
| 17 | class MsgpackSerializerTest extends \PHPUnit_Framework_TestCase |
||
| 18 | { |
||
| 19 | public function test_formats() |
||
| 20 | { |
||
| 21 | $serializer = new MsgpackSerializer(); |
||
| 22 | $this->assertInternalType('array', $serializer->getSupportedFormats()); |
||
| 23 | $this->assertEquals(['msgpack'], $serializer->getSupportedFormats()); |
||
| 24 | $this->assertInternalType('string', $serializer->getDefaultFormat()); |
||
| 25 | $this->assertEquals('msgpack', $serializer->getDefaultFormat()); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function test_supports() |
||
| 29 | { |
||
| 30 | $serializer = new MsgpackSerializer(); |
||
| 31 | $this->assertFalse($serializer->supportsFormat('json')); |
||
| 32 | $this->assertFalse($serializer->supportsFormat('xml')); |
||
| 33 | $this->assertTrue($serializer->supportsFormat('msgpack')); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function test_serialize() |
||
| 37 | { |
||
| 38 | $serializer = new MsgpackSerializer(); |
||
| 39 | $output = $serializer->serialize('foo', 'msgpack'); |
||
| 40 | $this->assertEquals('bar', $output); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |