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 |
||
| 8 | class IndirectFieldsTestAbstract extends AbstractEntityManagerTest |
||
| 9 | { |
||
| 10 | 1 | public function testIndirectId() |
|
| 11 | { |
||
| 12 | 1 | $repository = $this->getManager()->getRepository(IndirectIdEntity::class); |
|
| 13 | 1 | $this->getResponseMock()->append( |
|
| 14 | 1 | new Response( |
|
| 15 | 1 | 200, |
|
| 16 | 1 | [], |
|
| 17 | 1 | json_encode( |
|
| 18 | [ |
||
| 19 | 1 | 'jsonrpc' => '2.0', |
|
| 20 | 1 | 'id' => 'test', |
|
| 21 | 'result' => [ |
||
| 22 | 1 | 'some-long-api-field-name' => 241, |
|
| 23 | 1 | 'payload' => 'test', |
|
| 24 | 1 | ], |
|
| 25 | ] |
||
| 26 | 1 | ) |
|
| 27 | 1 | ) |
|
| 28 | 1 | ); |
|
| 29 | |||
| 30 | /** @var IndirectIdEntity $entity */ |
||
| 31 | 1 | $entity = $repository->find(241); |
|
| 32 | |||
| 33 | 1 | self::assertInstanceOf(IndirectIdEntity::class, $entity); |
|
| 34 | 1 | self::assertEquals(241, $entity->getId()); |
|
| 35 | 1 | self::assertEquals('test', $entity->getPayload()); |
|
| 36 | 1 | } |
|
| 37 | } |
||
| 38 |