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