Completed
Pull Request — master (#14)
by Pavel
04:24
created

EntityFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 58.44 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 45
loc 77
c 0
b 0
f 0
wmc 4
lcom 1
cbo 7
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testEntityLoading() 23 23 1
A testInheritanceLoading() 22 22 1
A testCompositeKeyLoading() 0 22 1
A getClientNames() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Bankiru\Api\Doctrine\Tests;
4
5
use Bankiru\Api\Doctrine\Test\Entity\CompositeKeyEntity;
6
use Bankiru\Api\Doctrine\Test\Entity\Sub\SubEntity;
7
use Bankiru\Api\Doctrine\Test\Entity\TestEntity;
8
9
class EntityFactoryTest extends AbstractEntityManagerTest
10
{
11 View Code Duplication
    public function testEntityLoading()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
    {
13
        $repository = $this->getManager()->getRepository(TestEntity::class);
14
15
        $this->getClient()->push(
16
            $this->getResponseMock(
17
                true,
18
                (object)[
19
                    'id'      => '1',
20
                    'payload' => 'test-payload',
21
                ]
22
23
            )
24
        );
25
26
        /** @var TestEntity $entity */
27
        $entity = $repository->find(1);
28
29
        self::assertInstanceOf(TestEntity::class, $entity);
30
        self::assertEquals(1, $entity->getId());
31
        self::assertInternalType('int', $entity->getId());
32
        self::assertEquals('test-payload', $entity->getPayload());
33
    }
34
35 View Code Duplication
    public function testInheritanceLoading()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $repository = $this->getManager()->getRepository(SubEntity::class);
38
        $this->getClient()->push(
39
            $this->getResponseMock(
40
                true,
41
                (object)[
42
                    'id'          => 2,
43
                    'payload'     => 'test-payload',
44
                    'sub-payload' => 'sub-payload',
45
                ]
46
            )
47
        );
48
49
        /** @var SubEntity $entity */
50
        $entity = $repository->find(2);
51
52
        self::assertInstanceOf(SubEntity::class, $entity);
53
        self::assertEquals(2, $entity->getId());
54
        self::assertEquals('test-payload', $entity->getPayload());
55
        self::assertEquals('sub-payload', $entity->getSubPayload());
56
    }
57
58
    public function testCompositeKeyLoading()
59
    {
60
        $repository = $this->getManager()->getRepository(CompositeKeyEntity::class);
61
        $this->getClient()->push(
62
            $this->getResponseMock(
63
                true,
64
                (object)[
65
                    'first_key'  => 2,
66
                    'second_key' => 'test',
67
                    'payload'    => 'test-payload',
68
                ]
69
            )
70
        );
71
72
        /** @var CompositeKeyEntity $entity */
73
        $entity = $repository->find(['firstKey' => 2, 'secondKey' => 'test']);
74
75
        self::assertInstanceOf(CompositeKeyEntity::class, $entity);
76
        self::assertEquals(2, $entity->getFirstKey());
77
        self::assertEquals('test', $entity->getSecondKey());
78
        self::assertEquals('test-payload', $entity->getPayload());
79
    }
80
81
    protected function getClientNames()
82
    {
83
        return array_merge(parent::getClientNames(), ['test-reference-client']);
84
    }
85
}
86