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 BinaryLoaderTest extends PHPUnit_Framework_TestCase |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 24 | */ |
||
| 25 | private $ioService; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
| 29 | */ |
||
| 30 | private $extensionGuesser; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var BinaryLoader |
||
| 34 | */ |
||
| 35 | private $binaryLoader; |
||
| 36 | |||
| 37 | protected function setUp() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @expectedException \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function testFindNotFound() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @expectedException \Liip\ImagineBundle\Exception\Binary\Loader\NotLoadableException |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function testFindMissing() |
|
| 74 | |||
| 75 | public function testFindBadPathRoot() |
||
| 76 | { |
||
| 77 | $path = 'var/site/storage/images/1/2/3/123-name/name.png'; |
||
| 78 | $this->ioService |
||
| 79 | ->expects($this->once()) |
||
| 80 | ->method('loadBinaryFile') |
||
| 81 | ->with($path) |
||
| 82 | ->will($this->throwException(new InvalidBinaryFileIdException($path))); |
||
| 83 | |||
| 84 | try { |
||
| 85 | $this->binaryLoader->find($path); |
||
| 86 | } catch (NotLoadableException $e) { |
||
| 87 | $this->assertContains( |
||
| 88 | "Suggested value: '1/2/3/123-name/name.png'", |
||
| 89 | $e->getMessage() |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | public function testFind() |
||
| 128 | } |
||
| 129 |