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 |
||
| 7 | class WebAdminUserHelperFactoryTest extends \PHPUnit_Framework_TestCase |
||
| 8 | { |
||
| 9 | public function testInvokingWebUserHelperShouldReturnWebAdminUserHelper() |
||
| 10 | { |
||
| 11 | $adminUserService = $this->getMockBuilder(\Admin\Service\AdminUserService::class) |
||
| 12 | ->disableOriginalConstructor() |
||
| 13 | ->getMockForAbstractClass(); |
||
| 14 | $container = $this->getMockBuilder(\Interop\Container\ContainerInterface::class) |
||
| 15 | ->setMethods(['get']) |
||
| 16 | ->getMockForAbstractClass(); |
||
| 17 | $container->expects(static::at(0)) |
||
| 18 | ->method('get') |
||
| 19 | ->will(static::returnValue($adminUserService)); |
||
| 20 | $webUserHelperFactory = new \Admin\Factory\View\Helper\WebAdminUserHelperFactory(); |
||
| 21 | static::assertInstanceOf(\Admin\View\Helper\WebAdminUserHelper::class, $webUserHelperFactory($container, 'test')); |
||
| 22 | } |
||
| 23 | } |
||
| 24 |