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 WebAdminUserHelperTest extends \PHPUnit_Framework_TestCase |
||
| 8 | { |
||
| 9 | public function testInvokingAdminUserHelperShouldReturnItSelf() |
||
| 10 | { |
||
| 11 | $adminUserService = $this->getMockBuilder(\Admin\Service\AdminUserService::class) |
||
| 12 | ->disableOriginalConstructor() |
||
| 13 | ->getMockForAbstractClass(); |
||
| 14 | $adminUserHelper = new \Admin\View\Helper\WebAdminUserHelper($adminUserService); |
||
| 15 | static::assertInstanceOf(\Admin\View\Helper\WebAdminUserHelper::class, $adminUserHelper()); |
||
| 16 | } |
||
| 17 | |||
| 18 | public function testGetRandomShouldReturnArray() |
||
| 19 | { |
||
| 20 | $adminUserService = $this->getMockBuilder(\Admin\Service\AdminUserService::class) |
||
| 21 | ->setMethods(['getForWeb']) |
||
| 22 | ->disableOriginalConstructor() |
||
| 23 | ->getMockForAbstractClass(); |
||
| 24 | $adminUserService->expects(static::once()) |
||
| 25 | ->method('getForWeb') |
||
| 26 | ->willReturn([]); |
||
| 27 | $adminUserHelper = new \Admin\View\Helper\WebAdminUserHelper($adminUserService); |
||
| 28 | static::assertSame([], $adminUserHelper->getRandom()); |
||
| 29 | } |
||
| 30 | } |
||
| 31 |