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
|
|
|
|
8
|
|
|
class ProxyTestAbstract extends AbstractEntityManagerTest |
9
|
|
|
{ |
10
|
|
|
public function testLazyProxy() |
11
|
|
|
{ |
12
|
|
|
$manager = $this->getManager(); |
13
|
|
|
|
14
|
|
|
$this->getClient()->push( |
15
|
|
|
$this->getResponseMock( |
16
|
|
|
true, |
17
|
|
|
(object)[ |
18
|
|
|
'id' => 2, |
19
|
|
|
'payload' => 'test-payload', |
20
|
|
|
'sub-payload' => 'sub-payload', |
21
|
|
|
] |
22
|
|
|
) |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
/** @var SubEntity|Proxy $entity */ |
26
|
|
|
$entity = $manager->getReference(SubEntity::class, 2); |
27
|
|
|
|
28
|
|
|
//Test that entity is a proxy and request was not send |
29
|
|
|
self::assertInstanceOf(Proxy::class, $entity); |
30
|
|
|
self::assertFalse($entity->__isInitialized()); |
|
|
|
|
31
|
|
|
self::assertGreaterThan(0, $this->getClient()->count()); |
32
|
|
|
|
33
|
|
|
//Test that we can obtain ID and request was still not sent |
34
|
|
|
self::assertEquals(2, $entity->getId()); |
|
|
|
|
35
|
|
|
self::assertInstanceOf(Proxy::class, $entity); |
36
|
|
|
self::assertFalse($entity->__isInitialized()); |
37
|
|
|
self::assertGreaterThan(0, $this->getClient()->count()); |
38
|
|
|
|
39
|
|
|
//Test that we can obtain data and request was sent |
40
|
|
|
self::assertInstanceOf(SubEntity::class, $entity); |
41
|
|
|
self::assertEquals('test-payload', $entity->getPayload()); |
|
|
|
|
42
|
|
|
self::assertEquals('sub-payload', $entity->getSubPayload()); |
|
|
|
|
43
|
|
|
|
44
|
|
|
//Test that we are still a Proxy object |
45
|
|
|
self::assertInstanceOf(Proxy::class, $entity); |
46
|
|
|
self::assertTrue($entity->__isInitialized()); |
47
|
|
|
self::assertEquals(0, $this->getClient()->count()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function testSimpleProxy() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$repository = $this->getManager()->getRepository(SubEntity::class); |
53
|
|
|
|
54
|
|
|
$this->getClient()->push( |
55
|
|
|
$this->getResponseMock( |
56
|
|
|
true, |
57
|
|
|
(object)[ |
58
|
|
|
'id' => 2, |
59
|
|
|
'payload' => 'test-payload', |
60
|
|
|
'sub-payload' => 'sub-payload', |
61
|
|
|
] |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
/** @var SubEntity|Proxy $entity */ |
66
|
|
|
$entity = $repository->find(2); |
67
|
|
|
|
68
|
|
|
//Test that we can obtain data and request was sent |
69
|
|
|
self::assertInstanceOf(SubEntity::class, $entity); |
70
|
|
|
self::assertEquals(2, $entity->getId()); |
|
|
|
|
71
|
|
|
self::assertEquals('test-payload', $entity->getPayload()); |
|
|
|
|
72
|
|
|
self::assertEquals('sub-payload', $entity->getSubPayload()); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
protected function getClientNames() |
76
|
|
|
{ |
77
|
|
|
return [self::DEFAULT_CLIENT, 'test-reference-client']; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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: