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
|
|
|
final 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) { |
|
|
|
|
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) { |
|
|
|
|
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
|
|
|
|
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.