1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Doctrine\Tests; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\Doctrine\Test\Entity\Sub\SubEntity; |
6
|
|
|
use Doctrine\Common\Proxy\Proxy; |
7
|
|
|
use ScayTrase\Api\Rpc\RpcRequestInterface; |
8
|
|
|
|
9
|
|
|
class ProxyTestAbstract extends AbstractEntityManagerTest |
10
|
|
|
{ |
11
|
|
|
public function testLazyProxy() |
12
|
|
|
{ |
13
|
|
|
$manager = $this->getManager(); |
14
|
|
|
|
15
|
|
|
$this->getClient()->push( |
16
|
|
|
$this->getResponseMock( |
17
|
|
|
true, |
18
|
|
|
(object)[ |
19
|
|
|
'id' => 2, |
20
|
|
|
'payload' => 'test-payload', |
21
|
|
|
'sub-payload' => 'sub-payload', |
22
|
|
|
] |
23
|
|
|
), |
24
|
|
|
function (RpcRequestInterface $request) { |
25
|
|
|
self::assertEquals('test-entity/find', $request->getMethod()); |
26
|
|
|
self::assertEquals(['id' => 2], $request->getParameters()); |
27
|
|
|
|
28
|
|
|
return true; |
29
|
|
|
} |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
/** @var SubEntity|Proxy $entity */ |
33
|
|
|
$entity = $manager->getReference(SubEntity::class, 2); |
34
|
|
|
|
35
|
|
|
//Test that entity is a proxy and request was not send |
36
|
|
|
self::assertInstanceOf(Proxy::class, $entity); |
37
|
|
|
self::assertFalse($entity->__isInitialized()); |
|
|
|
|
38
|
|
|
self::assertCount(1, $this->getClient()); |
39
|
|
|
|
40
|
|
|
//Test that we can obtain ID and request was still not sent |
41
|
|
|
self::assertEquals(2, $entity->getId()); |
|
|
|
|
42
|
|
|
self::assertInstanceOf(Proxy::class, $entity); |
43
|
|
|
self::assertFalse($entity->__isInitialized()); |
44
|
|
|
self::assertCount(1, $this->getClient()); |
45
|
|
|
|
46
|
|
|
//Test that we can obtain data and request was sent |
47
|
|
|
self::assertInstanceOf(SubEntity::class, $entity); |
48
|
|
|
self::assertEquals('test-payload', $entity->getPayload()); |
|
|
|
|
49
|
|
|
self::assertEquals('sub-payload', $entity->getSubPayload()); |
|
|
|
|
50
|
|
|
|
51
|
|
|
//Test that we are still a Proxy object |
52
|
|
|
self::assertInstanceOf(Proxy::class, $entity); |
53
|
|
|
self::assertTrue($entity->__isInitialized()); |
54
|
|
|
self::assertCount(0, $this->getClient()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function testSimpleProxy() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$repository = $this->getManager()->getRepository(SubEntity::class); |
60
|
|
|
|
61
|
|
|
$this->getClient()->push( |
62
|
|
|
$this->getResponseMock( |
63
|
|
|
true, |
64
|
|
|
(object)[ |
65
|
|
|
'id' => 2, |
66
|
|
|
'payload' => 'test-payload', |
67
|
|
|
'sub-payload' => 'sub-payload', |
68
|
|
|
] |
69
|
|
|
), |
70
|
|
|
function (RpcRequestInterface $request) { |
71
|
|
|
self::assertEquals('test-entity/find', $request->getMethod()); |
72
|
|
|
self::assertEquals(['id' => 2], $request->getParameters()); |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
/** @var SubEntity $entity */ |
79
|
|
|
$entity = $repository->find(2); |
80
|
|
|
|
81
|
|
|
//Test that we can obtain data and request was sent |
82
|
|
|
self::assertInstanceOf(SubEntity::class, $entity); |
83
|
|
|
self::assertEquals(2, $entity->getId()); |
84
|
|
|
self::assertEquals('test-payload', $entity->getPayload()); |
85
|
|
|
self::assertEquals('sub-payload', $entity->getSubPayload()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function getClientNames() |
89
|
|
|
{ |
90
|
|
|
return [self::DEFAULT_CLIENT, 'test-reference-client']; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: