Completed
Pull Request — master (#14)
by Pavel
03:40
created

CollectionLoadingTest::testFindBy()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 60
Code Lines 39

Duplication

Lines 24
Ratio 40 %

Importance

Changes 0
Metric Value
dl 24
loc 60
rs 9.5555
c 0
b 0
f 0
cc 3
eloc 39
nc 3
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Bankiru\Api\Doctrine\Tests;
4
5
use Bankiru\Api\Doctrine\Test\Entity\Sub\SubEntity;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use ScayTrase\Api\Rpc\RpcRequestInterface;
8
9
class CollectionLoadingTest extends AbstractEntityManagerTest
10
{
11
    public function testFindBy()
12
    {
13
        $repository = $this->getManager()->getRepository(SubEntity::class);
14
15
        $this->getClient()->push(
16
            $this->getResponseMock(
17
                true,
18
                [
19
                    (object)[
20
                        'id'             => '1',
21
                        'payload'        => 'test-payload-1',
22
                        'sub-payload'    => 'sub-payload',
23
                        'string-payload' => null,
24
                    ],
25
                    (object)[
26
                        'id'             => '2',
27
                        'payload'        => 'test-payload-2',
28
                        'sub-payload'    => 'sub-payload',
29
                        'string-payload' => 123456,
30
                    ],
31
                    (object)[
32
                        'id'             => '3',
33
                        'payload'        => 'test-payload-3',
34
                        'sub-payload'    => 'sub-payload',
35
                        'string-payload' => 'sub-payload',
36
                    ],
37
                ]
38
            ),
39 View Code Duplication
            function (RpcRequestInterface $request) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
40
                self::assertEquals('test-entity/search', $request->getMethod());
41
                self::assertEquals(
42
                    [
43
                        'criteria' => ['sub-payload' => 'sub-payload'],
44
                        'order'    => [],
45
                        'limit'    => null,
46
                        'offset'   => null,
47
                    ],
48
                    $request->getParameters()
49
                );
50
51
                return true;
52
            }
53
        );
54
55
        /** @var SubEntity[]|ArrayCollection $entities */
56
        $entities = $repository->findBy(['subPayload' => 'sub-payload']);
57
        self::assertInternalType('array', $entities);
58
        self::assertCount(3, $entities);
59
60 View Code Duplication
        foreach ($entities as $entity) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
61
            self::assertInternalType('int', $entity->getId());
62
            self::assertInstanceOf(SubEntity::class, $entity);
63
            self::assertEquals('test-payload-' . $entity->getId(), $entity->getPayload());
64
            self::assertEquals('sub-payload', $entity->getSubPayload());
65
66
            if (null !== $entity->getStringPayload()) {
67
                self::assertInternalType('string', $entity->getStringPayload());
68
            }
69
        }
70
    }
71
72
    protected function getClientNames()
73
    {
74
        return [self::DEFAULT_CLIENT, 'test-reference-client'];
75
    }
76
}
77