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 |
||
| 20 | class VichSerializableFieldTest extends \PHPUnit_Framework_TestCase |
||
| 21 | { |
||
| 22 | public function testValueOption() |
||
| 23 | { |
||
| 24 | $annotation = new VichSerializableField(['value' => 'photoFile']); |
||
| 25 | |||
| 26 | $this->assertEquals('photoFile', $annotation->getField()); |
||
| 27 | $this->assertTrue($annotation->isIncludeHost()); |
||
| 28 | } |
||
| 29 | |||
| 30 | public function testFieldOption() |
||
| 31 | { |
||
| 32 | $annotation = new VichSerializableField(['field' => 'photoFile']); |
||
| 33 | |||
| 34 | $this->assertEquals('photoFile', $annotation->getField()); |
||
| 35 | $this->assertTrue($annotation->isIncludeHost()); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function testValueAndIncludeHostOptions() |
||
| 39 | { |
||
| 40 | $annotation = new VichSerializableField(['value' => 'photoFile', 'includeHost' => false]); |
||
| 41 | |||
| 42 | $this->assertEquals('photoFile', $annotation->getField()); |
||
| 43 | $this->assertFalse($annotation->isIncludeHost()); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @expectedException \LogicException |
||
| 48 | */ |
||
| 49 | public function testAnnotationWithoutOptions() |
||
| 50 | { |
||
| 51 | new VichSerializableField([]); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @expectedException \LogicException |
||
| 56 | */ |
||
| 57 | public function testAnnotationWithoutIncludeHostOption() |
||
| 58 | { |
||
| 59 | new VichSerializableField(['includeHost' => false]); |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @expectedException \InvalidArgumentException |
||
| 64 | */ |
||
| 65 | public function testWrongTypeForValueOption() |
||
| 66 | { |
||
| 67 | new VichSerializableField(['value' => 123]); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @expectedException \InvalidArgumentException |
||
| 72 | */ |
||
| 73 | public function testWrongTypeForFieldOption() |
||
| 74 | { |
||
| 75 | new VichSerializableField(['field' => 123]); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @expectedException \InvalidArgumentException |
||
| 80 | */ |
||
| 81 | public function testWrongTypeForFieldIncludeHost() |
||
| 82 | { |
||
| 83 | new VichSerializableField(['value' => 'photoFile', 'includeHost' => 123]); |
||
| 84 | } |
||
| 85 | } |
||
| 86 |