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

CollectionLoadingTest::testFindBy()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 46
Code Lines 30

Duplication

Lines 10
Ratio 21.74 %

Importance

Changes 0
Metric Value
dl 10
loc 46
c 0
b 0
f 0
rs 8.9411
cc 3
eloc 30
nc 3
nop 0
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
8
class CollectionLoadingTest extends AbstractEntityManagerTest
9
{
10
    public function testFindBy()
11
    {
12
        $repository = $this->getManager()->getRepository(SubEntity::class);
13
14
        $this->getClient()->push(
15
            $this->getResponseMock(
16
                true,
17
                [
18
                    (object)[
19
                        'id'             => '1',
20
                        'payload'        => 'test-payload-1',
21
                        'sub-payload'    => 'sub-payload',
22
                        'string-payload' => null,
23
                    ],
24
                    (object)[
25
                        'id'             => '2',
26
                        'payload'        => 'test-payload-2',
27
                        'sub-payload'    => 'sub-payload',
28
                        'string-payload' => 123456,
29
                    ],
30
                    (object)[
31
                        'id'             => '3',
32
                        'payload'        => 'test-payload-3',
33
                        'sub-payload'    => 'sub-payload',
34
                        'string-payload' => 'sub-payload',
35
                    ],
36
                ]
37
            )
38
        );
39
40
        /** @var SubEntity[]|ArrayCollection $entities */
41
        $entities = $repository->findBy(['subPayload' => 'sub-payload']);
42
        self::assertInternalType('array', $entities);
43
        self::assertCount(3, $entities);
44
45 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...
46
            self::assertInternalType('int', $entity->getId());
47
            self::assertInstanceOf(SubEntity::class, $entity);
48
            self::assertEquals('test-payload-'.$entity->getId(), $entity->getPayload());
49
            self::assertEquals('sub-payload', $entity->getSubPayload());
50
51
            if (null !== $entity->getStringPayload()) {
52
                self::assertInternalType('string', $entity->getStringPayload());
53
            }
54
        }
55
    }
56
57
    protected function getClientNames()
58
    {
59
        return [self::DEFAULT_CLIENT, 'test-reference-client'];
60
    }
61
}
62