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 |
||
| 11 | class EsiHelperTest extends \PHPUnit_Framework_TestCase |
||
| 12 | { |
||
| 13 | public function testFragmentRenderer() |
||
| 14 | { |
||
| 15 | $observer = $this->prophesize('\Symfony\Component\HttpKernel\Fragment\FragmentHandler'); |
||
| 16 | $observer->render('test', 'esi', [])->willReturn('test')->shouldBeCalled(); |
||
| 17 | |||
| 18 | $helper = new EsiHelper($observer->reveal()); |
||
| 19 | $result = $helper->handle('test', []); |
||
| 20 | |||
| 21 | $this->assertInstanceOf('\LightnCandy\SafeString', $result); |
||
| 22 | $this->assertSame('test', (string)$result); |
||
| 23 | } |
||
| 24 | } |
||
| 25 |