1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mapado\RestClientSdk\Tests\Units; |
4
|
|
|
|
5
|
|
|
use atoum; |
6
|
|
|
use Mapado\RestClientSdk\Mapping as RestMapping; |
7
|
|
|
use Mapado\RestClientSdk\Mapping\Attribute; |
8
|
|
|
use Mapado\RestClientSdk\Mapping\ClassMetadata; |
9
|
|
|
use Mapado\RestClientSdk\Mapping\Relation; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* UnitOfWork |
13
|
|
|
* |
14
|
|
|
* @uses atoum |
15
|
|
|
* @author Julien Petit <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class UnitOfWork extends atoum |
18
|
|
|
{ |
19
|
|
|
private $unitOfWork; |
|
|
|
|
20
|
|
|
|
21
|
|
|
public function testRegister() |
22
|
|
|
{ |
23
|
|
|
$mapping = $this->getMapping(); |
24
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
25
|
|
|
|
26
|
|
|
$ticket = (object) [ |
27
|
|
|
'firstname' => 'foo', |
28
|
|
|
'lastname' => 'bar', |
29
|
|
|
'email' => '[email protected]', |
30
|
|
|
]; |
31
|
|
|
$unitOfWork->registerClean('@id1', $ticket); |
32
|
|
|
$this |
33
|
|
|
->then |
34
|
|
|
->variable($unitOfWork->getDirtyEntity('@id1')) |
35
|
|
|
->isEqualTo($ticket) |
36
|
|
|
; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSimpleEntity() |
40
|
|
|
{ |
41
|
|
|
$mapping = $this->getMapping(); |
42
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
43
|
|
|
|
44
|
|
|
$this |
45
|
|
|
->array($unitOfWork->getDirtyData( |
46
|
|
|
[ |
47
|
|
|
'@id' => '/v12/carts/1', |
48
|
|
|
], |
49
|
|
|
[ |
50
|
|
|
'@id' => '/v12/carts/1', |
51
|
|
|
], |
52
|
|
|
$this->getCartMetadata() |
53
|
|
|
)) |
54
|
|
|
->isEqualTo([]) |
55
|
|
|
->then |
56
|
|
|
->array($unitOfWork->getDirtyData( |
57
|
|
|
[ |
58
|
|
|
'@id' => '/v12/carts/1', |
59
|
|
|
'status' => 'payed', |
60
|
|
|
'order' => '/v12/orders/1', |
61
|
|
|
], |
62
|
|
|
[ |
63
|
|
|
'@id' => '/v12/carts/1', |
64
|
|
|
'status' => 'payed', |
65
|
|
|
'order' => '/v12/orders/1', |
66
|
|
|
], |
67
|
|
|
$this->getCartMetadata() |
68
|
|
|
)) |
69
|
|
|
->isEqualTo([]) |
70
|
|
|
->then |
71
|
|
|
->array($unitOfWork->getDirtyData( |
72
|
|
|
[ |
73
|
|
|
'@id' => '/v12/carts/1', |
74
|
|
|
'status' => 'payed', |
75
|
|
|
], |
76
|
|
|
[ |
77
|
|
|
'@id' => '/v12/carts/1', |
78
|
|
|
'status' => 'waiting', |
79
|
|
|
], |
80
|
|
|
$this->getCartMetadata() |
81
|
|
|
)) |
82
|
|
|
->isEqualTo(['status' => 'payed']) |
83
|
|
|
->then |
84
|
|
|
->array($unitOfWork->getDirtyData( |
85
|
|
|
[ |
86
|
|
|
'@id' => '/v12/carts/2', |
87
|
|
|
'status' => 'payed', |
88
|
|
|
], |
89
|
|
|
[ |
90
|
|
|
'@id' => '/v12/carts/1', |
91
|
|
|
'status' => 'waiting', |
92
|
|
|
], |
93
|
|
|
$this->getCartMetadata() |
94
|
|
|
)) |
95
|
|
|
->isEqualTo([ |
96
|
|
|
'@id' => '/v12/carts/2', |
97
|
|
|
'status' => 'payed', |
98
|
|
|
]) |
99
|
|
|
->then |
100
|
|
|
->array($unitOfWork->getDirtyData( |
101
|
|
|
[ |
102
|
|
|
'@id' => '/v12/carts/1', |
103
|
|
|
'status' => 'payed', |
104
|
|
|
'someData' => [ |
105
|
|
|
'foo' => 'bar', |
106
|
|
|
'loo' => 'baz', |
107
|
|
|
], |
108
|
|
|
], |
109
|
|
|
[ |
110
|
|
|
'@id' => '/v12/carts/1', |
111
|
|
|
'status' => 'payed', |
112
|
|
|
'someData' => [ |
113
|
|
|
'foo' => 'bar', |
114
|
|
|
], |
115
|
|
|
], |
116
|
|
|
$this->getCartMetadata() |
117
|
|
|
)) |
118
|
|
|
->isEqualTo([ |
119
|
|
|
'someData' => [ |
120
|
|
|
'foo' => 'bar', |
121
|
|
|
'loo' => 'baz', |
122
|
|
|
], |
123
|
|
|
]) |
124
|
|
|
; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testManyToOneRelation() |
128
|
|
|
{ |
129
|
|
|
$mapping = $this->getMapping(); |
130
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
131
|
|
|
|
132
|
|
|
$this |
133
|
|
|
->array($unitOfWork->getDirtyData( |
134
|
|
|
[ |
135
|
|
|
'@id' => '/v12/carts/1', |
136
|
|
|
'order' => '/v1/orders/2', |
137
|
|
|
], |
138
|
|
|
[ |
139
|
|
|
'@id' => '/v12/carts/1', |
140
|
|
|
'order' => [ '@id' => '/v1/orders/1' ], |
141
|
|
|
], |
142
|
|
|
$this->getCartMetadata() |
143
|
|
|
)) |
144
|
|
|
->isEqualTo([ |
145
|
|
|
'order' => '/v1/orders/2', |
146
|
|
|
]) |
147
|
|
|
|
148
|
|
|
->then |
149
|
|
|
->array($unitOfWork->getDirtyData( |
150
|
|
|
[ |
151
|
|
|
'@id' => '/v12/carts/1', |
152
|
|
|
'order' => [ |
153
|
|
|
'@id' => '/v1/orders/2', |
154
|
|
|
] |
155
|
|
|
], |
156
|
|
|
[ |
157
|
|
|
'@id' => '/v12/carts/1', |
158
|
|
|
'order' => '/v1/orders/1', |
159
|
|
|
], |
160
|
|
|
$this->getCartMetadata() |
161
|
|
|
)) |
162
|
|
|
->isEqualTo([ |
163
|
|
|
'order' => [ |
164
|
|
|
'@id' => '/v1/orders/2', |
165
|
|
|
], |
166
|
|
|
]) |
167
|
|
|
|
168
|
|
|
->then |
169
|
|
|
->array($unitOfWork->getDirtyData( |
170
|
|
|
[ |
171
|
|
|
'@id' => '/v12/carts/1', |
172
|
|
|
'order' => [ |
173
|
|
|
'@id' => '/v1/orders/2', |
174
|
|
|
'status' => 'payed', |
175
|
|
|
] |
176
|
|
|
], |
177
|
|
|
[ |
178
|
|
|
'@id' => '/v12/carts/1', |
179
|
|
|
'order' => [ |
180
|
|
|
'@id' => '/v1/orders/1', |
181
|
|
|
'status' => 'payed', |
182
|
|
|
], |
183
|
|
|
], |
184
|
|
|
$this->getCartMetadata() |
185
|
|
|
)) |
186
|
|
|
->isEqualTo([ |
187
|
|
|
'order' => [ |
188
|
|
|
'@id' => '/v1/orders/2', |
189
|
|
|
], |
190
|
|
|
]) |
191
|
|
|
|
192
|
|
|
->then |
193
|
|
|
->array($unitOfWork->getDirtyData( |
194
|
|
|
[ |
195
|
|
|
'@id' => '/v12/carts/1', |
196
|
|
|
'order' => [ |
197
|
|
|
'@id' => '/v1/orders/2', |
198
|
|
|
'status' => 'payed', |
199
|
|
|
] |
200
|
|
|
], |
201
|
|
|
[ |
202
|
|
|
'@id' => '/v12/carts/1', |
203
|
|
|
'order' => [ |
204
|
|
|
'@id' => '/v1/orders/1', |
205
|
|
|
'status' => 'waiting', |
206
|
|
|
], |
207
|
|
|
], |
208
|
|
|
$this->getCartMetadata() |
209
|
|
|
)) |
210
|
|
|
->isEqualTo([ |
211
|
|
|
'order' => [ |
212
|
|
|
'@id' => '/v1/orders/2', |
213
|
|
|
'status' => 'payed', |
214
|
|
|
], |
215
|
|
|
]) |
216
|
|
|
; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function dontcommittestOneToManyRelation() |
220
|
|
|
{ |
221
|
|
|
$mapping = $this->getMapping(); |
222
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
223
|
|
|
|
224
|
|
|
$this |
225
|
|
|
->array($unitOfWork->getDirtyData( |
226
|
|
|
[ |
227
|
|
|
'@id' => '/v12/carts/1', |
228
|
|
|
'cartItemList' => [ |
229
|
|
|
'/v1/cart_items/1', |
230
|
|
|
'/v1/cart_items/2', |
231
|
|
|
], |
232
|
|
|
], |
233
|
|
|
[ |
234
|
|
|
'@id' => '/v12/carts/1', |
235
|
|
|
'cartItemList' => [ |
236
|
|
|
'/v1/cart_items/1', |
237
|
|
|
'/v1/cart_items/2', |
238
|
|
|
], |
239
|
|
|
], |
240
|
|
|
$this->getCartMetadata() |
241
|
|
|
)) |
242
|
|
|
->isEqualTo([]) |
243
|
|
|
|
244
|
|
|
->array($unitOfWork->getDirtyData( |
245
|
|
|
[ |
246
|
|
|
'@id' => '/v12/carts/1', |
247
|
|
|
'cartItemList' => [ |
248
|
|
|
'/v1/cart_items/1', |
249
|
|
|
'/v1/cart_items/2', |
250
|
|
|
], |
251
|
|
|
], |
252
|
|
|
[ |
253
|
|
|
'@id' => '/v12/carts/1', |
254
|
|
|
'cartItemList' => [ |
255
|
|
|
'/v1/cart_items/2', |
256
|
|
|
'/v1/cart_items/1', |
257
|
|
|
], |
258
|
|
|
], |
259
|
|
|
$this->getCartMetadata() |
260
|
|
|
)) |
261
|
|
|
->isEqualTo([ |
262
|
|
|
'cartItemList' => [ |
263
|
|
|
'/v1/cart_items/1', |
264
|
|
|
'/v1/cart_items/2', |
265
|
|
|
], |
266
|
|
|
]) |
267
|
|
|
|
268
|
|
|
->array($unitOfWork->getDirtyData( |
269
|
|
|
[ |
270
|
|
|
'@id' => '/v12/carts/1', |
271
|
|
|
'cartItemList' => [ |
272
|
|
|
'/v1/cart_items/2', |
273
|
|
|
], |
274
|
|
|
], |
275
|
|
|
[ |
276
|
|
|
'@id' => '/v12/carts/1', |
277
|
|
|
'cartItemList' => [ |
278
|
|
|
'/v1/cart_items/1', |
279
|
|
|
'/v1/cart_items/2', |
280
|
|
|
], |
281
|
|
|
], |
282
|
|
|
$this->getCartMetadata() |
283
|
|
|
)) |
284
|
|
|
->isEqualTo([ |
285
|
|
|
'cartItemList' => [ |
286
|
|
|
'/v1/cart_items/2', |
287
|
|
|
], |
288
|
|
|
]) |
289
|
|
|
|
290
|
|
|
->array($unitOfWork->getDirtyData( |
291
|
|
|
[ |
292
|
|
|
'@id' => '/v12/carts/1', |
293
|
|
|
'cartItemList' => [ |
294
|
|
|
'/v1/cart_items/1', |
295
|
|
|
'/v1/cart_items/2', |
296
|
|
|
'/v1/cart_items/3', |
297
|
|
|
], |
298
|
|
|
], |
299
|
|
|
[ |
300
|
|
|
'@id' => '/v12/carts/1', |
301
|
|
|
'cartItemList' => [ |
302
|
|
|
'/v1/cart_items/1', |
303
|
|
|
'/v1/cart_items/2', |
304
|
|
|
], |
305
|
|
|
], |
306
|
|
|
$this->getCartMetadata() |
307
|
|
|
)) |
308
|
|
|
->isEqualTo([ |
309
|
|
|
'cartItemList' => [ |
310
|
|
|
'/v1/cart_items/1', |
311
|
|
|
'/v1/cart_items/2', |
312
|
|
|
'/v1/cart_items/3', |
313
|
|
|
], |
314
|
|
|
]) |
315
|
|
|
; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
View Code Duplication |
public function testNoChanges() |
|
|
|
|
319
|
|
|
{ |
320
|
|
|
$mapping = $this->getMapping(); |
321
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
322
|
|
|
|
323
|
|
|
$this |
324
|
|
|
->given($newSerializedModel = [ |
325
|
|
|
'@id' => '/v12/carts/1', |
326
|
|
|
'cartItemList' => [ |
327
|
|
|
'/v12/cart_items/1', |
328
|
|
|
'/v12/cart_items/2', |
329
|
|
|
'/v12/cart_items/3', |
330
|
|
|
], |
331
|
|
|
]) |
332
|
|
|
->then |
333
|
|
|
->variable($unitOfWork->getDirtyData( |
334
|
|
|
$newSerializedModel, |
335
|
|
|
[ |
336
|
|
|
'@id' => '/v12/carts/1', |
337
|
|
|
'cartItemList' => [ |
338
|
|
|
'/v12/cart_items/1', |
339
|
|
|
'/v12/cart_items/2', |
340
|
|
|
'/v12/cart_items/3', |
341
|
|
|
], |
342
|
|
|
], |
343
|
|
|
$this->getCartMetadata() |
344
|
|
|
)) |
345
|
|
|
->isEqualTo( |
346
|
|
|
[ |
347
|
|
|
] |
348
|
|
|
) |
349
|
|
|
->then |
350
|
|
|
->variable($unitOfWork->getDirtyData( |
351
|
|
|
[ |
352
|
|
|
'@id' => '/v12/carts/1', |
353
|
|
|
'cartItemList' => [ |
354
|
|
|
[ |
355
|
|
|
'@id' => '/v12/cart_items/1', |
356
|
|
|
'amount' => 1, |
357
|
|
|
], |
358
|
|
|
[ |
359
|
|
|
'@id' => '/v12/cart_items/2', |
360
|
|
|
'amount' => 1, |
361
|
|
|
], |
362
|
|
|
], |
363
|
|
|
], |
364
|
|
|
[ |
365
|
|
|
'@id' => '/v12/carts/1', |
366
|
|
|
'cartItemList' => [ |
367
|
|
|
[ |
368
|
|
|
'@id' => '/v12/cart_items/1', |
369
|
|
|
'amount' => 1, |
370
|
|
|
], |
371
|
|
|
[ |
372
|
|
|
'@id' => '/v12/cart_items/2', |
373
|
|
|
'amount' => 1, |
374
|
|
|
], |
375
|
|
|
], |
376
|
|
|
], |
377
|
|
|
$this->getCartMetadata() |
378
|
|
|
)) |
379
|
|
|
->isEqualTo( |
380
|
|
|
[ |
381
|
|
|
] |
382
|
|
|
) |
383
|
|
|
; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
View Code Duplication |
public function testNoMetadata() |
|
|
|
|
387
|
|
|
{ |
388
|
|
|
$mapping = $this->getMapping(); |
389
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
390
|
|
|
|
391
|
|
|
$this |
392
|
|
|
->given($newSerializedModel = [ |
393
|
|
|
'@id' => '/v12/carts/1', |
394
|
|
|
'cartInfo' => [ |
395
|
|
|
[ |
396
|
|
|
'firstname' => 'john', |
397
|
|
|
'lastname' => 'doe', |
398
|
|
|
], |
399
|
|
|
], |
400
|
|
|
]) |
401
|
|
|
->then |
402
|
|
|
->variable($unitOfWork->getDirtyData( |
403
|
|
|
$newSerializedModel, |
404
|
|
|
[ |
405
|
|
|
'@id' => '/v12/carts/1', |
406
|
|
|
'cartInfo' => [ |
407
|
|
|
[ |
408
|
|
|
'firstname' => 'john', |
409
|
|
|
'lastname' => 'doe', |
410
|
|
|
], |
411
|
|
|
], |
412
|
|
|
], |
413
|
|
|
$this->getCartMetadata() |
414
|
|
|
)) |
415
|
|
|
->isEqualTo( |
416
|
|
|
[ |
417
|
|
|
] |
418
|
|
|
) |
419
|
|
|
->then |
420
|
|
|
->variable($unitOfWork->getDirtyData( |
421
|
|
|
[ |
422
|
|
|
'@id' => '/v12/carts/1', |
423
|
|
|
'cartItemList' => [ |
424
|
|
|
[ |
425
|
|
|
'@id' => '/v12/cart_items/1', |
426
|
|
|
'amount' => 1, |
427
|
|
|
], |
428
|
|
|
[ |
429
|
|
|
'@id' => '/v12/cart_items/2', |
430
|
|
|
'amount' => 1, |
431
|
|
|
], |
432
|
|
|
], |
433
|
|
|
], |
434
|
|
|
[ |
435
|
|
|
'@id' => '/v12/carts/1', |
436
|
|
|
'cartItemList' => [ |
437
|
|
|
[ |
438
|
|
|
'@id' => '/v12/cart_items/1', |
439
|
|
|
'amount' => 1, |
440
|
|
|
], |
441
|
|
|
[ |
442
|
|
|
'@id' => '/v12/cart_items/2', |
443
|
|
|
'amount' => 1, |
444
|
|
|
], |
445
|
|
|
], |
446
|
|
|
], |
447
|
|
|
$this->getCartMetadata() |
448
|
|
|
)) |
449
|
|
|
->isEqualTo( |
450
|
|
|
[ |
451
|
|
|
] |
452
|
|
|
) |
453
|
|
|
; |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
public function testRemoveItem() |
457
|
|
|
{ |
458
|
|
|
$mapping = $this->getMapping(); |
459
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
460
|
|
|
|
461
|
|
|
$this |
462
|
|
|
->then |
463
|
|
|
->variable($unitOfWork->getDirtyData( |
464
|
|
|
[ |
465
|
|
|
'@id' => '/v12/carts/1', |
466
|
|
|
'cartItemList' => [ |
467
|
|
|
'/v12/cart_items/1', |
468
|
|
|
'/v12/cart_items/2', |
469
|
|
|
], |
470
|
|
|
], |
471
|
|
|
[ |
472
|
|
|
'@id' => '/v12/carts/1', |
473
|
|
|
'cartItemList' => [ |
474
|
|
|
'/v12/cart_items/1', |
475
|
|
|
'/v12/cart_items/2', |
476
|
|
|
'/v12/cart_items/3', |
477
|
|
|
], |
478
|
|
|
], |
479
|
|
|
$this->getCartMetadata() |
480
|
|
|
)) |
481
|
|
|
->isEqualTo( |
482
|
|
|
[ |
483
|
|
|
'cartItemList' => [ |
484
|
|
|
'/v12/cart_items/1', |
485
|
|
|
'/v12/cart_items/2', |
486
|
|
|
], |
487
|
|
|
] |
488
|
|
|
) |
489
|
|
|
->then |
490
|
|
|
->variable($unitOfWork->getDirtyData( |
491
|
|
|
[ |
492
|
|
|
'@id' => '/v12/carts/1', |
493
|
|
|
'cartItemList' => [ |
494
|
|
|
'/v12/cart_items/1', |
495
|
|
|
'/v12/cart_items/3', |
496
|
|
|
], |
497
|
|
|
], |
498
|
|
|
[ |
499
|
|
|
'@id' => '/v12/carts/1', |
500
|
|
|
'cartItemList' => [ |
501
|
|
|
'/v12/cart_items/1', |
502
|
|
|
'/v12/cart_items/2', |
503
|
|
|
'/v12/cart_items/3', |
504
|
|
|
], |
505
|
|
|
], |
506
|
|
|
$this->getCartMetadata() |
507
|
|
|
)) |
508
|
|
|
->isEqualTo( |
509
|
|
|
[ |
510
|
|
|
'cartItemList' => [ |
511
|
|
|
'/v12/cart_items/1', |
512
|
|
|
'/v12/cart_items/3', |
513
|
|
|
], |
514
|
|
|
] |
515
|
|
|
) |
516
|
|
|
->then |
517
|
|
|
->variable($unitOfWork->getDirtyData( |
518
|
|
|
[ |
519
|
|
|
'@id' => '/v12/carts/1', |
520
|
|
|
'cartItemList' => [ |
521
|
|
|
[ |
522
|
|
|
'@id' => '/v12/cart_items/1', |
523
|
|
|
'amount' => 2, |
524
|
|
|
], |
525
|
|
|
], |
526
|
|
|
], |
527
|
|
|
[ |
528
|
|
|
'@id' => '/v12/carts/1', |
529
|
|
|
'cartItemList' => [ |
530
|
|
|
[ |
531
|
|
|
'@id' => '/v12/cart_items/1', |
532
|
|
|
'amount' => 2, |
533
|
|
|
], |
534
|
|
|
[ |
535
|
|
|
'@id' => '/v12/cart_items/2', |
536
|
|
|
'amount' => 1, |
537
|
|
|
], |
538
|
|
|
], |
539
|
|
|
], |
540
|
|
|
$this->getCartMetadata() |
541
|
|
|
)) |
542
|
|
|
->isEqualTo( |
543
|
|
|
[ |
544
|
|
|
'cartItemList' => [ |
545
|
|
|
[ |
546
|
|
|
'@id' => '/v12/cart_items/1', |
547
|
|
|
], |
548
|
|
|
], |
549
|
|
|
] |
550
|
|
|
) |
551
|
|
|
->then |
552
|
|
|
->variable($unitOfWork->getDirtyData( |
553
|
|
|
[ |
554
|
|
|
'@id' => '/v12/carts/1', |
555
|
|
|
'cartItemList' => [ |
556
|
|
|
[ |
557
|
|
|
'@id' => '/v12/cart_items/2', |
558
|
|
|
'amount' => 1, |
559
|
|
|
], |
560
|
|
|
], |
561
|
|
|
], |
562
|
|
|
[ |
563
|
|
|
'@id' => '/v12/carts/1', |
564
|
|
|
'cartItemList' => [ |
565
|
|
|
[ |
566
|
|
|
'@id' => '/v12/cart_items/1', |
567
|
|
|
'amount' => 2, |
568
|
|
|
], |
569
|
|
|
[ |
570
|
|
|
'@id' => '/v12/cart_items/2', |
571
|
|
|
'amount' => 1, |
572
|
|
|
], |
573
|
|
|
], |
574
|
|
|
], |
575
|
|
|
$this->getCartMetadata() |
576
|
|
|
)) |
577
|
|
|
->isEqualTo( |
578
|
|
|
[ |
579
|
|
|
'cartItemList' => [ |
580
|
|
|
[ |
581
|
|
|
'@id' => '/v12/cart_items/2', |
582
|
|
|
], |
583
|
|
|
], |
584
|
|
|
] |
585
|
|
|
) |
586
|
|
|
->then |
587
|
|
|
->array($unitOfWork->getDirtyData( |
588
|
|
|
[ |
589
|
|
|
'@id' => '/v12/carts/1', |
590
|
|
|
'cartItemList' => [ |
591
|
|
|
[ |
592
|
|
|
'@id' => '/v12/cart_items/2', |
593
|
|
|
'amount' => 2, |
594
|
|
|
], |
595
|
|
|
], |
596
|
|
|
], |
597
|
|
|
[ |
598
|
|
|
'@id' => '/v12/carts/1', |
599
|
|
|
'cartItemList' => [ |
600
|
|
|
[ |
601
|
|
|
'@id' => '/v12/cart_items/1', |
602
|
|
|
'amount' => 2, |
603
|
|
|
], |
604
|
|
|
[ |
605
|
|
|
'@id' => '/v12/cart_items/2', |
606
|
|
|
'amount' => 1, |
607
|
|
|
], |
608
|
|
|
], |
609
|
|
|
], |
610
|
|
|
$this->getCartMetadata() |
611
|
|
|
)) |
612
|
|
|
->isEqualTo( |
613
|
|
|
[ |
614
|
|
|
'cartItemList' => [ |
615
|
|
|
[ |
616
|
|
|
'@id' => '/v12/cart_items/2', |
617
|
|
|
'amount' => 2, |
618
|
|
|
], |
619
|
|
|
], |
620
|
|
|
] |
621
|
|
|
) |
622
|
|
|
; |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
public function testAddItem() |
626
|
|
|
{ |
627
|
|
|
$mapping = $this->getMapping(); |
628
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
629
|
|
|
|
630
|
|
|
$this |
631
|
|
|
->then |
632
|
|
|
->variable($unitOfWork->getDirtyData( |
633
|
|
|
[ |
634
|
|
|
'@id' => '/v12/carts/1', |
635
|
|
|
'cartItemList' => [ |
636
|
|
|
'/v12/cart_items/1', |
637
|
|
|
'/v12/cart_items/2', |
638
|
|
|
'/v12/cart_items/3', |
639
|
|
|
], |
640
|
|
|
], |
641
|
|
|
[ |
642
|
|
|
'@id' => '/v12/carts/1', |
643
|
|
|
'cartItemList' => [ |
644
|
|
|
'/v12/cart_items/1', |
645
|
|
|
'/v12/cart_items/2', |
646
|
|
|
], |
647
|
|
|
], |
648
|
|
|
$this->getCartMetadata() |
649
|
|
|
)) |
650
|
|
|
->isEqualTo( |
651
|
|
|
[ |
652
|
|
|
'cartItemList' => [ |
653
|
|
|
'/v12/cart_items/1', |
654
|
|
|
'/v12/cart_items/2', |
655
|
|
|
'/v12/cart_items/3', |
656
|
|
|
], |
657
|
|
|
] |
658
|
|
|
) |
659
|
|
|
->then |
660
|
|
|
->variable($unitOfWork->getDirtyData( |
661
|
|
|
[ |
662
|
|
|
'@id' => '/v12/carts/1', |
663
|
|
|
'cartItemList' => [ |
664
|
|
|
[ |
665
|
|
|
'@id' => '/v12/cart_items/1', |
666
|
|
|
'amount' => 1, |
667
|
|
|
], |
668
|
|
|
[ |
669
|
|
|
'@id' => '/v12/cart_items/2', |
670
|
|
|
'amount' => 1, |
671
|
|
|
], |
672
|
|
|
], |
673
|
|
|
], |
674
|
|
|
[ |
675
|
|
|
'@id' => '/v12/carts/1', |
676
|
|
|
'cartItemList' => [ |
677
|
|
|
[ |
678
|
|
|
'@id' => '/v12/cart_items/1', |
679
|
|
|
'amount' => 1, |
680
|
|
|
], |
681
|
|
|
], |
682
|
|
|
], |
683
|
|
|
$this->getCartMetadata() |
684
|
|
|
)) |
685
|
|
|
->isEqualTo( |
686
|
|
|
[ |
687
|
|
|
'cartItemList' => [ |
688
|
|
|
[ |
689
|
|
|
'@id' => '/v12/cart_items/1', |
690
|
|
|
], |
691
|
|
|
[ |
692
|
|
|
'@id' => '/v12/cart_items/2', |
693
|
|
|
'amount' => 1, |
694
|
|
|
], |
695
|
|
|
], |
696
|
|
|
] |
697
|
|
|
) |
698
|
|
|
; |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
public function testSendOnlyDirty() |
702
|
|
|
{ |
703
|
|
|
$mapping = $this->getMapping(); |
704
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
705
|
|
|
|
706
|
|
|
$this |
707
|
|
|
->then |
708
|
|
|
->variable($unitOfWork->getDirtyData( |
709
|
|
|
[ |
710
|
|
|
'@id' => '/v12/carts/1', |
711
|
|
|
'cartItemList' => [ |
712
|
|
|
[ |
713
|
|
|
'@id' => '/v12/cart_items/1', |
714
|
|
|
'amount' => 2, |
715
|
|
|
], |
716
|
|
|
[ |
717
|
|
|
'@id' => '/v12/cart_items/2', |
718
|
|
|
'amount' => 1, |
719
|
|
|
], |
720
|
|
|
], |
721
|
|
|
], |
722
|
|
|
[ |
723
|
|
|
'@id' => '/v12/carts/1', |
724
|
|
|
'cartItemList' => [ |
725
|
|
|
[ |
726
|
|
|
'@id' => '/v12/cart_items/1', |
727
|
|
|
'amount' => 1, |
728
|
|
|
], |
729
|
|
|
[ |
730
|
|
|
'@id' => '/v12/cart_items/2', |
731
|
|
|
'amount' => 1, |
732
|
|
|
], |
733
|
|
|
], |
734
|
|
|
], |
735
|
|
|
$this->getCartMetadata() |
736
|
|
|
)) |
737
|
|
|
->isEqualTo( |
738
|
|
|
[ |
739
|
|
|
'cartItemList' => [ |
740
|
|
|
[ |
741
|
|
|
'@id' => '/v12/cart_items/1', |
742
|
|
|
'amount' => 2, |
743
|
|
|
], |
744
|
|
|
], |
745
|
|
|
] |
746
|
|
|
) |
747
|
|
|
->then |
748
|
|
|
->variable($unitOfWork->getDirtyData( |
749
|
|
|
[ |
750
|
|
|
'@id' => '/v12/carts/1', |
751
|
|
|
'status' => 'ok', |
752
|
|
|
'clientPhoneNumber' => '+33123456789', |
753
|
|
|
], |
754
|
|
|
[ |
755
|
|
|
'@id' => '/v12/carts/1', |
756
|
|
|
'status' => 'ko', |
757
|
|
|
'clientPhoneNumber' => '+33123456789', |
758
|
|
|
], |
759
|
|
|
$this->getCartMetadata() |
760
|
|
|
)) |
761
|
|
|
->isEqualTo( |
762
|
|
|
[ |
763
|
|
|
'status' => 'ok', |
764
|
|
|
] |
765
|
|
|
) |
766
|
|
|
->then |
767
|
|
|
->variable($unitOfWork->getDirtyData( |
768
|
|
|
[ |
769
|
|
|
'cartItemList' => [ |
770
|
|
|
[ |
771
|
|
|
'@id' => '/v12/cart_items/1', |
772
|
|
|
'amount' => 1, |
773
|
|
|
'cartItemDetailList' => [ |
774
|
|
|
[ |
775
|
|
|
'@id' => '/v12/cart_item_details/1', |
776
|
|
|
'name' => '', |
777
|
|
|
], |
778
|
|
|
], |
779
|
|
|
], |
780
|
|
|
[ |
781
|
|
|
'@id' => '/v12/cart_items/2', |
782
|
|
|
'amount' => 1, |
783
|
|
|
], |
784
|
|
|
[ |
785
|
|
|
'@id' => '/v12/cart_items/3', |
786
|
|
|
'amount' => 1, |
787
|
|
|
'cartItemDetailList' => [ |
788
|
|
|
[ |
789
|
|
|
'@id' => '/v12/cart_item_details/2', |
790
|
|
|
'name' => '', |
791
|
|
|
], |
792
|
|
|
], |
793
|
|
|
], |
794
|
|
|
], |
795
|
|
|
], |
796
|
|
|
[ |
797
|
|
|
'cartItemList' => [ |
798
|
|
|
[ |
799
|
|
|
'@id' => '/v12/cart_items/1', |
800
|
|
|
'amount' => 2, |
801
|
|
|
'cartItemDetailList' => [ |
802
|
|
|
'@id' => '/v12/cart_item_details/1', |
803
|
|
|
'name' => 'foo', |
804
|
|
|
], |
805
|
|
|
], |
806
|
|
|
[ |
807
|
|
|
'@id' => '/v12/cart_items/3', |
808
|
|
|
'amount' => 1, |
809
|
|
|
], |
810
|
|
|
], |
811
|
|
|
], |
812
|
|
|
$this->getCartMetadata() |
813
|
|
|
)) |
814
|
|
|
->isEqualTo( |
815
|
|
|
[ |
816
|
|
|
'cartItemList' => [ |
817
|
|
|
[ |
818
|
|
|
'amount' => 1, |
819
|
|
|
'cartItemDetailList' => [ |
820
|
|
|
[ |
821
|
|
|
'@id' => '/v12/cart_item_details/1', |
822
|
|
|
'name' => '', |
823
|
|
|
], |
824
|
|
|
], |
825
|
|
|
'@id' => '/v12/cart_items/1', |
826
|
|
|
], |
827
|
|
|
[ |
828
|
|
|
'@id' => '/v12/cart_items/2', |
829
|
|
|
'amount' => 1, |
830
|
|
|
], |
831
|
|
|
[ |
832
|
|
|
'@id' => '/v12/cart_items/3', |
833
|
|
|
'cartItemDetailList' => [ |
834
|
|
|
[ |
835
|
|
|
'@id' => '/v12/cart_item_details/2', |
836
|
|
|
'name' => '', |
837
|
|
|
] |
838
|
|
|
], |
839
|
|
|
], |
840
|
|
|
] |
841
|
|
|
] |
842
|
|
|
) |
843
|
|
|
; |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
public function testNoMetadataChangeArray() |
847
|
|
|
{ |
848
|
|
|
$mapping = $this->getMapping(); |
849
|
|
|
$unitOfWork = $this->newTestedInstance($mapping); |
850
|
|
|
|
851
|
|
|
$this |
852
|
|
|
->given($newSerializedModel = [ |
853
|
|
|
'@id' => '/v12/carts/1', |
854
|
|
|
'cartInfo' => [ |
855
|
|
|
[ |
856
|
|
|
'firstname' => 'jane', |
857
|
|
|
'lastname' => 'doe', |
858
|
|
|
], |
859
|
|
|
], |
860
|
|
|
]) |
861
|
|
|
->then |
862
|
|
|
->variable($unitOfWork->getDirtyData( |
863
|
|
|
$newSerializedModel, |
864
|
|
|
[ |
865
|
|
|
'@id' => '/v12/carts/1', |
866
|
|
|
'cartInfo' => [ |
867
|
|
|
[ |
868
|
|
|
'firstname' => 'john', |
869
|
|
|
'lastname' => 'doe', |
870
|
|
|
], |
871
|
|
|
], |
872
|
|
|
], |
873
|
|
|
$this->getCartMetadata() |
874
|
|
|
)) |
875
|
|
|
->isEqualTo( |
876
|
|
|
[ |
877
|
|
|
'cartInfo' => [ |
878
|
|
|
[ |
879
|
|
|
'firstname' => 'jane', |
880
|
|
|
'lastname' => 'doe', |
881
|
|
|
], |
882
|
|
|
], |
883
|
|
|
] |
884
|
|
|
) |
885
|
|
|
|
886
|
|
|
->then |
887
|
|
|
->variable($unitOfWork->getDirtyData( |
888
|
|
|
[ |
889
|
|
|
'@id' => '/v12/carts/1', |
890
|
|
|
'order' => [ |
891
|
|
|
'@id' => '/v12/orders/1', |
892
|
|
|
'customerPaidAmount' => 1500, |
893
|
|
|
'status' => 'awaiting_payment', |
894
|
|
|
], |
895
|
|
|
], |
896
|
|
|
[ |
897
|
|
|
'@id' => '/v12/carts/1', |
898
|
|
|
'order' => [ |
899
|
|
|
'@id' => '/v12/orders/1', |
900
|
|
|
'customerPaidAmount' => 1000, |
901
|
|
|
'status' => 'awaiting_payment', |
902
|
|
|
], |
903
|
|
|
], |
904
|
|
|
$this->getCartMetadata() |
905
|
|
|
)) |
906
|
|
|
->isEqualTo( |
907
|
|
|
[ |
908
|
|
|
'order' => [ |
909
|
|
|
'@id' => '/v12/orders/1', |
910
|
|
|
'customerPaidAmount' => 1500, |
911
|
|
|
], |
912
|
|
|
] |
913
|
|
|
) |
914
|
|
|
|
915
|
|
|
; |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
private function getMapping() |
919
|
|
|
{ |
920
|
|
|
$mapping = $mapping = new RestMapping(); |
921
|
|
|
$mapping->setMapping([ |
922
|
|
|
$this->getOrderMetadata(), |
923
|
|
|
$this->getCartMetadata(), |
924
|
|
|
$this->getCartItemMetadata(), |
925
|
|
|
$this->getCartItemDetailMetadata(), |
926
|
|
|
]); |
927
|
|
|
|
928
|
|
|
return $mapping; |
929
|
|
|
} |
930
|
|
|
|
931
|
|
View Code Duplication |
private function getOrderMetadata() |
|
|
|
|
932
|
|
|
{ |
933
|
|
|
$orderMetadata = new ClassMetadata( |
934
|
|
|
'orders', |
935
|
|
|
'Mapado\RestClientSdk\Tests\Model\JsonLd\Order', |
936
|
|
|
'' |
937
|
|
|
); |
938
|
|
|
|
939
|
|
|
$orderMetadata->setAttributeList([ |
940
|
|
|
new Attribute('@id', 'id', 'string', true), |
941
|
|
|
new Attribute('customerPaidAmount', 'customerPaidAmount', 'int'), |
942
|
|
|
new Attribute('status'), |
943
|
|
|
]); |
944
|
|
|
|
945
|
|
|
$orderMetadata->setRelationList([ |
946
|
|
|
]); |
947
|
|
|
|
948
|
|
|
return $orderMetadata; |
949
|
|
|
} |
950
|
|
|
|
951
|
|
View Code Duplication |
private function getCartMetadata() |
|
|
|
|
952
|
|
|
{ |
953
|
|
|
$cartMetadata = new ClassMetadata( |
954
|
|
|
'carts', |
955
|
|
|
'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart', |
956
|
|
|
'' |
957
|
|
|
); |
958
|
|
|
|
959
|
|
|
$cartMetadata->setAttributeList([ |
960
|
|
|
new Attribute('@id', 'id', 'string', true), |
961
|
|
|
new Attribute('status'), |
962
|
|
|
new Attribute('clientPhoneNumber', 'clientPhoneNumber', 'phone_number'), |
963
|
|
|
new Attribute('createdAt', 'createdAt', 'datetime'), |
964
|
|
|
new Attribute('cart_items', 'cartItemList'), |
965
|
|
|
new Attribute('order'), |
966
|
|
|
]); |
967
|
|
|
|
968
|
|
|
$cartMetadata->setRelationList([ |
969
|
|
|
new Relation('cartItemList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'), |
970
|
|
|
new Relation('order', Relation::MANY_TO_ONE, 'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'), |
971
|
|
|
]); |
972
|
|
|
|
973
|
|
|
return $cartMetadata; |
974
|
|
|
} |
975
|
|
|
|
976
|
|
View Code Duplication |
private function getCartItemMetadata() |
|
|
|
|
977
|
|
|
{ |
978
|
|
|
$cartItemMetadata = new ClassMetadata( |
979
|
|
|
'cart_items', |
980
|
|
|
'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem', |
981
|
|
|
'' |
982
|
|
|
); |
983
|
|
|
|
984
|
|
|
$cartItemMetadata->setAttributeList([ |
985
|
|
|
new Attribute('@id', 'id', 'string', true), |
986
|
|
|
new Attribute('amount'), |
987
|
|
|
new Attribute('cartItemDetailList'), |
988
|
|
|
]); |
989
|
|
|
|
990
|
|
|
$cartItemMetadata->setRelationList([ |
991
|
|
|
new Relation('cartItemDetailList', Relation::ONE_TO_MANY, 'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail'), |
992
|
|
|
]); |
993
|
|
|
|
994
|
|
|
return $cartItemMetadata; |
995
|
|
|
} |
996
|
|
|
|
997
|
|
View Code Duplication |
private function getCartItemDetailMetadata() |
|
|
|
|
998
|
|
|
{ |
999
|
|
|
$cartItemDetailMetadata = new ClassMetadata( |
1000
|
|
|
'cart_item_details', |
1001
|
|
|
'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItemDetail', |
1002
|
|
|
'' |
1003
|
|
|
); |
1004
|
|
|
|
1005
|
|
|
$cartItemDetailMetadata->setAttributeList([ |
1006
|
|
|
new Attribute('@id', 'id', 'string', true), |
1007
|
|
|
new Attribute('name'), |
1008
|
|
|
]); |
1009
|
|
|
|
1010
|
|
|
return $cartItemDetailMetadata; |
1011
|
|
|
} |
1012
|
|
|
} |
1013
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.