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