1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\Doctrine\Tests; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\Doctrine\Test\Entity\TestEntity; |
6
|
|
|
use Bankiru\Api\Doctrine\Test\Entity\TestReference; |
7
|
|
|
use ScayTrase\Api\Rpc\RpcRequestInterface; |
8
|
|
|
|
9
|
|
|
class CommitTest extends AbstractEntityManagerTest |
10
|
|
|
{ |
11
|
|
|
public function testSimpleCommit() |
12
|
|
|
{ |
13
|
|
|
$entity = new TestReference(); |
14
|
|
|
|
15
|
|
|
$this->getClient('test-reference-client')->push( |
16
|
|
|
$this->getResponseMock(true, 241), |
17
|
|
|
function (RpcRequestInterface $request) { |
18
|
|
|
self::assertEquals('test-reference/create', $request->getMethod()); |
19
|
|
|
self::assertEquals( |
20
|
|
|
[ |
21
|
|
|
'reference-payload' => '', |
22
|
|
|
'owner' => null, |
23
|
|
|
], |
24
|
|
|
$request->getParameters() |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
return true; |
28
|
|
|
} |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
$this->getManager()->persist($entity); |
32
|
|
|
$this->getManager()->flush(); |
33
|
|
|
|
34
|
|
|
self::assertNotNull($entity->getId()); |
35
|
|
|
self::assertEquals(241, $entity->getId()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testChainCommitWithRelation() |
39
|
|
|
{ |
40
|
|
|
$entity = new TestReference(); |
41
|
|
|
$parent = new TestEntity(); |
42
|
|
|
$entity->setOwner($parent); |
43
|
|
|
|
44
|
|
|
$this->getClient()->push( |
45
|
|
|
$this->getResponseMock(true, 42), |
46
|
|
|
function (RpcRequestInterface $request) { |
47
|
|
|
self::assertEquals('test-entity/create', $request->getMethod()); |
48
|
|
|
self::assertEquals( |
49
|
|
|
[ |
50
|
|
|
'payload' => '', |
51
|
|
|
'parent' => null, |
52
|
|
|
], |
53
|
|
|
$request->getParameters() |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
return true; |
57
|
|
|
} |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->getClient('test-reference-client')->push( |
61
|
|
|
$this->getResponseMock(true, 241), |
62
|
|
|
function (RpcRequestInterface $request) { |
63
|
|
|
self::assertEquals('test-reference/create', $request->getMethod()); |
64
|
|
|
self::assertEquals( |
65
|
|
|
[ |
66
|
|
|
'reference-payload' => '', |
67
|
|
|
'owner' => 42, |
68
|
|
|
], |
69
|
|
|
$request->getParameters() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->getManager()->persist($entity); |
77
|
|
|
$this->getManager()->persist($parent); |
78
|
|
|
$this->getManager()->flush(); |
79
|
|
|
|
80
|
|
|
self::assertNotNull($parent->getId()); |
81
|
|
|
self::assertEquals(42, $parent->getId()); |
82
|
|
|
|
83
|
|
|
self::assertNotNull($entity->getId()); |
84
|
|
|
self::assertEquals(241, $entity->getId()); |
85
|
|
|
|
86
|
|
|
self::assertEquals($entity->getOwner(), $parent); |
87
|
|
|
|
88
|
|
|
return $entity; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testChainUpdateWithRelation() |
92
|
|
|
{ |
93
|
|
|
$entity = $this->testChainCommitWithRelation(); |
94
|
|
|
|
95
|
|
|
$oldParent = $entity->getOwner(); |
96
|
|
|
$newParent = new TestEntity(); |
97
|
|
|
$this->getClient()->push( |
98
|
|
|
$this->getResponseMock(true, 17), |
99
|
|
|
function (RpcRequestInterface $request) { |
100
|
|
|
self::assertEquals('test-entity/create', $request->getMethod()); |
101
|
|
|
self::assertEquals( |
102
|
|
|
[ |
103
|
|
|
'payload' => '', |
104
|
|
|
'parent' => null, |
105
|
|
|
], |
106
|
|
|
$request->getParameters() |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
return true; |
110
|
|
|
} |
111
|
|
|
); |
112
|
|
|
$this->getClient('test-reference-client')->push( |
113
|
|
|
$this->getResponseMock(true, null), |
114
|
|
|
function (RpcRequestInterface $request) { |
115
|
|
|
self::assertEquals('test-reference/patch', $request->getMethod()); |
116
|
|
|
self::assertEquals( |
117
|
|
|
[ |
118
|
|
|
'owner' => 17, |
119
|
|
|
], |
120
|
|
|
$request->getParameters() |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
return true; |
124
|
|
|
} |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$entity->setOwner($newParent); |
128
|
|
|
|
129
|
|
|
$this->getManager()->persist($newParent); |
130
|
|
|
$this->getManager()->flush(); |
131
|
|
|
|
132
|
|
|
self::assertNotNull($newParent->getId()); |
133
|
|
|
self::assertEquals(17, $newParent->getId()); |
134
|
|
|
|
135
|
|
|
self::assertNotNull($entity->getId()); |
136
|
|
|
self::assertEquals(241, $entity->getId()); |
137
|
|
|
|
138
|
|
|
self::assertEquals($entity->getOwner(), $newParent); |
139
|
|
|
|
140
|
|
|
self::assertNotSame($newParent, $oldParent); |
141
|
|
|
self::assertFalse($oldParent->getReferences()->contains($entity)); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testRemove() |
145
|
|
|
{ |
146
|
|
|
$entity = new TestReference(); |
147
|
|
|
|
148
|
|
|
$this->getClient('test-reference-client')->push($this->getResponseMock(true, 241)); |
149
|
|
|
|
150
|
|
|
$this->getManager()->persist($entity); |
151
|
|
|
$this->getManager()->flush(); |
152
|
|
|
|
153
|
|
|
self::assertNotNull($entity->getId()); |
154
|
|
|
self::assertEquals(241, $entity->getId()); |
155
|
|
|
|
156
|
|
|
$this->getClient('test-reference-client')->push($this->getResponseMock(true, null)); |
157
|
|
|
|
158
|
|
|
$this->getManager()->remove($entity); |
159
|
|
|
$this->getManager()->flush(); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
protected function getClientNames() |
163
|
|
|
{ |
164
|
|
|
return array_merge(parent::getClientNames(), ['test-reference-client']); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|