Completed
Pull Request — master (#58)
by
unknown
06:56
created

EntityRepository::testUnitOfWork()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 212
Code Lines 127

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 212
rs 8.2857
cc 1
eloc 127
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\UnitOfWork;
9
use Mapado\RestClientSdk\Mapping\ClassMetadata;
10
use Mapado\RestClientSdk\Mapping\Driver\AnnotationDriver;
11
use Symfony\Component\Cache\Adapter\ArrayAdapter;
12
13
/**
14
 * Class EntityRepository
15
 * @author Julien Deniau <[email protected]>
16
 */
17
class EntityRepository extends atoum
18
{
19
    private $mockedRestClient;
20
21
    private $mockedSdk;
22
23
    private $mockedHydrator;
24
25
    private $repository;
26
27
    private $mapping;
28
29
    private $unitOfWork;
30
31
    public function beforeTestMethod($method)
32
    {
33
        $this->mockGenerator->orphanize('__construct');
34
        $this->mockedSdk = new \mock\Mapado\RestClientSdk\SdkClient();
35
        $mockedHydrator = new \mock\Mapado\RestClientSdk\Model\ModelHydrator($this->mockedSdk);
36
        $this->calling($this->mockedSdk)->getModelHydrator = $mockedHydrator;
37
38
        $this->mockGenerator->orphanize('__construct');
39
        $this->mockedRestClient = new \mock\Mapado\RestClientSdk\RestClient();
40
        // $this->resetMock($this->mockedRestClient);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
42
        $this->mockedHydrator = new \mock\Mapado\RestClientSdk\Model\ModelHydrator($this->mockedSdk);
43
        $this->calling($this->mockedSdk)->getModelHydrator = $this->mockedHydrator;
44
45
        $this->unitOfWork = new UnitOfWork();
46
47
        $this->mapping = new RestMapping('v12');
48
        $this->mapping->setMapping([
49
            new ClassMetadata(
50
                'orders',
51
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Model',
52
                'mock\Mapado\RestClientSdk\EntityRepository'
53
            ),
54
        ]);
55
56
        $this->calling($this->mockedSdk)->getMapping = $this->mapping;
57
58
        $this->repository = new \mock\Mapado\RestClientSdk\EntityRepository(
59
            $this->mockedSdk,
60
            $this->mockedRestClient,
61
            $this->unitOfWork,
62
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Model'
63
        );
64
    }
65
66
    /**
67
     * testFind
68
     *
69
     * @access public
70
     * @return void
71
     */
72
    public function testFind()
73
    {
74
        $this->calling($this->mockedRestClient)->get = [];
75
76
        $this
77
            ->if($this->repository->find('1'))
78
            ->then
79
                ->mock($this->mockedRestClient)
80
                    ->call('get')
81
                        ->withArguments('v12/orders/1')->once()
82
83
            ->given($this->resetMock($this->mockedRestClient))
84
            ->if($this->repository->find('v12/orders/999'))
85
            ->then
86
                ->mock($this->mockedRestClient)
87
                    ->call('get')
88
                        ->withArguments('v12/orders/999')->once()
89
90
            ->if($this->repository->findAll())
91
            ->then
92
                ->mock($this->mockedRestClient)
93
                    ->call('get')
94
                        ->withArguments('v12/orders')->once()
95
96
            ->if($this->repository->findOneByFoo('bar'))
97
            ->then
98
                ->mock($this->mockedRestClient)
99
                    ->call('get')
100
                        ->withArguments('v12/orders?foo=bar')->once()
101
                ->mock($this->mockedHydrator)
102
                    ->call('hydrate')
103
                        ->twice()
104
105
            ->if($this->repository->findByFoo('baz'))
106
            ->then
107
                ->mock($this->mockedRestClient)
108
                    ->call('get')
109
                        ->withArguments('v12/orders?foo=baz')->once()
110
                ->mock($this->mockedHydrator)
111
                    ->call('hydrateList')
112
                        ->twice()
113
        ;
114
    }
115
116
    /**
117
     * testFindWithQueryParameters
118
     *
119
     * @access public
120
     * @return void
121
     */
122
    public function testFindWithQueryParameters()
123
    {
124
        $this->calling($this->mockedRestClient)->get = [];
125
126
        $this
127
            ->if($this->repository->find('1', [ 'foo' => 'bar', 'bar'  => 'baz' ]))
128
            ->then
129
                ->mock($this->mockedRestClient)
130
                    ->call('get')
131
                        ->withArguments('v12/orders/1?foo=bar&bar=baz')->once()
132
        ;
133
    }
134
135
    /**
136
     * testFindWithCache
137
     *
138
     * @access public
139
     * @return void
140
     */
141
    public function testFindWithCache()
142
    {
143
        $mockOrder1 = new \mock\entity;
144
        $mockOrder2 = new \mock\entity;
145
        $mockOrder3 = new \mock\entity;
146
        $this->calling($mockOrder1)->getId = 'v12/orders/1';
147
        $this->calling($mockOrder2)->getId = 'v12/orders/2';
148
        $this->calling($mockOrder3)->getId = 'v12/orders/3';
149
150
        $this->calling($this->mockedHydrator)->hydrate = $mockOrder1;
151
        $this->calling($this->mockedHydrator)->hydrateList = [$mockOrder1, $mockOrder2, $mockOrder3];
152
153
        $arrayAdapter = new ArrayAdapter(0, false);
154
        $this->calling($this->mockedSdk)->getCacheItemPool = $arrayAdapter;
155
        $this->calling($this->mockedSdk)->getCachePrefix = 'test_prefix_';
156
157
        $this->calling($this->mockedRestClient)->get = [];
158
159
        $this->calling($this->mockedHydrator)->convertId[0] = 'v12/orders/1';
160
        $this->calling($this->mockedHydrator)->convertId[1] = 'v12/orders/1';
161
        $this->calling($this->mockedHydrator)->convertId[4] = 'v12/orders/3';
162
163
        $this
164
            ->if($this->repository->find(1))
165
            ->and($this->repository->find(1))
166
            ->and($this->repository->find(1, ['foo' => 'bar']))
167
            ->then
168
                ->mock($this->mockedRestClient)
169
                    ->call('get')
170
                        ->withArguments('v12/orders/1')->once()
171
                    ->call('get')
172
                        ->withArguments('v12/orders/1?foo=bar')->once()
173
174
            // find all
175
            ->if($this->repository->findAll())
176
            ->and($this->repository->findAll())
177
            ->if($this->repository->find(3))
178
            ->then
179
                ->mock($this->mockedRestClient)
180
                    ->call('get')
181
                        ->withArguments('v12/orders')->once()
182
                    ->call('get')
183
                        ->withArguments('v12/orders/3')->never()
184
185
            // find by
186
            ->given($this->resetMock($this->mockedRestClient))
187
                ->and($this->mockedSdk->getCacheItemPool()->clear())
188
189
            ->if($this->repository->findBy([ 'foo' => 'bar', 'bar'  => 'baz' ]))
190
            ->and($this->repository->findBy([ 'foo' => 'bar', 'bar'  => 'baz' ]))
191
            ->if($this->repository->find(1))
192
            ->then
193
                ->mock($this->mockedRestClient)
194
                    ->call('get')
195
                        ->withArguments('v12/orders?foo=bar&bar=baz')->once()
196
                    ->call('get')
197
                        ->withArguments('v12/orders/1')->never()
198
199
            // find by something
200
            ->given($this->resetMock($this->mockedRestClient))
201
202
            ->if($this->repository->findByBar('baz'))
203
                ->and($this->repository->findByBar('baz'))
204
                ->and($this->repository->find(1))
205
            ->then
206
                ->mock($this->mockedRestClient)
207
                    ->call('get')
208
                        ->withArguments('v12/orders?bar=baz')->once()
209
                    ->call('get')
210
                        ->withArguments('v12/orders/1')->never()
211
212
            // find one by
213
            ->given($this->resetMock($this->mockedRestClient))
214
215
            ->if($this->repository->findOneBy([ 'foo' => 'baz', 'bar'  => 'bar' ]))
216
            ->and($this->repository->findOneBy([ 'foo' => 'baz', 'bar'  => 'bar' ]))
217
            ->then
218
                ->mock($this->mockedRestClient)
219
                    ->call('get')
220
                        ->withArguments('v12/orders?foo=baz&bar=bar')->once()
221
222
            // find one by thing
223
            ->given($this->resetMock($this->mockedRestClient))
224
225
            ->if($this->repository->findOneByFoo('bar'))
226
            ->and($this->repository->findOneByFoo('bar'))
227
            ->then
228
                ->mock($this->mockedRestClient)
229
                    ->call('get')
230
                        ->withArguments('v12/orders?foo=bar')->once()
231
232
            // find one by with data already in cache
233
            ->given($this->resetMock($this->mockedRestClient))
234
            ->if($this->repository->findOneBy([ 'foo' => 'bar', 'bar'  => 'baz' ]))
235
            ->then
236
                ->mock($this->mockedRestClient)
237
                    ->call('get')
238
                        ->withArguments('v12/orders?foo=bar&bar=baz')->never()
239
        ;
240
    }
241
242
    /**
243
     * testClearCacheAfterUpdate
244
     *
245
     * @access public
246
     *
247
     * @return void
248
     */
249
    public function testClearCacheAfterUpdate()
250
    {
251
        $mapping = new RestMapping('/v12');
252
        $mapping->setMapping([
253
            new ClassMetadata(
254
                'products',
255
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Product',
256
                'mock\Mapado\RestClientSdk\EntityRepository'
257
            ),
258
        ]);
259
260
        $this->calling($this->mockedSdk)->getMapping = $mapping;
261
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
262
263
264
        $product1 = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Product;
265
        $product2 = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Product;
266
        $product3 = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Product;
267
        $product1->setId('/v12/products/1');
268
        $product2->setId('/v12/products/2');
269
        $product3->setId('/v12/products/3');
270
271
        $this->calling($this->mockedHydrator)->hydrate = $product1;
272
        $this->calling($this->mockedHydrator)->hydrateList = [$product1, $product2, $product3];
273
274
        $arrayAdapter = new ArrayAdapter(0, false);
275
        $this->calling($this->mockedSdk)->getCacheItemPool = $arrayAdapter;
276
        $this->calling($this->mockedSdk)->getCachePrefix = 'test_prefix_';
277
278
        $this->calling($this->mockedRestClient)->get = $product1;
279
        $this->calling($this->mockedRestClient)->put = $product1;
280
        $this->calling($this->mockedRestClient)->delete = null;
281
282
        $repository = new \mock\Mapado\RestClientSdk\EntityRepository(
283
            $this->mockedSdk,
284
            $this->mockedRestClient,
285
            $this->unitOfWork,
286
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'
287
        );
288
289
        $this
290
            ->if($repository->find(1))
291
            ->then
292
                ->boolean($arrayAdapter->hasItem('test_prefix__v12_products_1'))
293
                    ->isTrue()
294
295
            ->if($repository->find(1))
296
            ->then
297
                ->mock($this->mockedRestClient)
298
                    ->call('get')
299
                        ->withArguments('/v12/products/1')->once()
300
301
            // after update
302
            ->if($repository->update($product1))
303
                ->boolean($arrayAdapter->hasItem('test_prefix__v12_products_1'))
304
                    ->isFalse()
305
306
            ->if($repository->find(1))
307
            ->then
308
                ->mock($this->mockedRestClient)
309
                    ->call('get')
310
                        ->withArguments('/v12/products/1')->twice()
311
312
            // after deletion
313
            ->if($repository->remove($product1))
314
            ->then
315
                ->boolean($arrayAdapter->hasItem('test_prefix__v12_products_1'))
316
                    ->isFalse()
317
        ;
318
    }
319
320
    public function testCacheWithIriAsId()
321
    {
322
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../cache/');
323
        $mapping = new RestMapping();
324
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../Model/Issue46/'));
325
326
        $this->calling($this->mockedSdk)->getMapping = $mapping;
327
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
328
329
        $section1 = new \Mapado\RestClientSdk\Tests\Model\Issue46\Section;
330
        $section1->setIri('/sections/1');
331
332
        $this->calling($this->mockedHydrator)->hydrate = $section1;
333
        $this->calling($this->mockedHydrator)->hydrateList = [$section1];
334
335
        $arrayAdapter = new ArrayAdapter(0, false);
336
        $this->calling($this->mockedSdk)->getCacheItemPool = $arrayAdapter;
337
        $this->calling($this->mockedSdk)->getCachePrefix = 'test_prefix_';
338
339
        $this->calling($this->mockedRestClient)->get = $section1;
340
        $this->calling($this->mockedRestClient)->put = $section1;
341
        $this->calling($this->mockedRestClient)->delete = null;
342
343
        $repository = new \mock\Mapado\RestClientSdk\EntityRepository(
344
            $this->mockedSdk,
345
            $this->mockedRestClient,
346
            $this->unitOfWork,
347
            'Mapado\RestClientSdk\Tests\Model\Issue46\Section'
348
        );
349
350
        $this
351
            ->if($repository->findBy(['section' => $section1]))
352
           ->then
353
               ->mock($this->mockedRestClient)
354
                   ->call('get')
355
                       ->withArguments('/sections?section=%2Fsections%2F1')->once()
356
357
            ->if($repository->findAll())
358
            ->then
359
                ->boolean($arrayAdapter->hasItem('test_prefix__sections_1'))
360
                    ->isTrue()
361
362
           ->if($repository->find(1))
363
           ->then
364
               ->mock($this->mockedRestClient)
365
                   ->call('get')
366
                       ->withArguments('/sections/1')->never()
367
368
            // after update
369
            ->if($repository->update($section1))
370
                ->boolean($arrayAdapter->hasItem('test_prefix__sections_1'))
371
                    ->isFalse()
372
            ->then
373
                ->mock($this->mockedRestClient)
374
                    ->call('put')
375
                        ->withArguments('/sections/1')->once()
376
377
            ->if($repository->find(1))
378
            ->then
379
                ->mock($this->mockedRestClient)
380
                    ->call('get')
381
                        ->withArguments('/sections/1')->once()
382
383
            // after deletion
384
            ->if($repository->remove($section1))
385
            ->then
386
                ->boolean($arrayAdapter->hasItem('test_prefix__sections_1'))
387
                    ->isFalse()
388
        ;
389
    }
390
391
    /**
392
     * testFindNotFound
393
     *
394
     * @access public
395
     * @return void
396
     */
397
    public function testFindNotFound()
398
    {
399
        $this->calling($this->mockedRestClient)->get = null;
400
401
        $this
402
            ->variable($this->repository->find('1'))
403
            ->isNull()
404
        ;
405
    }
406
407
    public function testFindOneByObject()
408
    {
409
        $mapping = new RestMapping('v12');
410
        $mapping->setMapping([
411
            new ClassMetadata(
412
                'carts',
413
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
414
                'mock\Mapado\RestClientSdk\EntityRepository'
415
            ),
416
            new ClassMetadata(
417
                'cart_items',
418
                'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
419
                'mock\Mapado\RestClientSdk\EntityRepository'
420
            ),
421
        ]);
422
423
        $this->calling($this->mockedSdk)->getMapping = $mapping;
424
425
        $this->calling($this->mockedRestClient)->get = [];
426
427
        $cartItemRepository = new \mock\Mapado\RestClientSdk\EntityRepository(
428
            $this->mockedSdk,
429
            $this->mockedRestClient,
430
            $this->unitOfWork,
431
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'
432
        );
433
434
435
        $cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart;
436
        $cart->setId(1);
437
438
        $this
439
            ->given($cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart)
440
                ->and($cart->setId(1))
441
            ->if($cartItemRepository->findOneByCart($cart))
442
            ->then
443
                ->mock($this->mockedRestClient)
444
                    ->call('get')
445
                        ->withArguments('v12/cart_items?cart=1')->once()
446
447
            // test with unmapped class
448
            ->given($cart = new \mock\stdClass)
449
            ->if($cartItemRepository->findOneByCart($cart))
450
            ->then
451
                ->mock($this->mockedRestClient)
452
                    ->call('get')
453
                        ->withArguments('v12/cart_items?')->once()
454
        ;
455
    }
456
457
    public function testWithoutMappingPrefix()
458
    {
459
        $mapping = new RestMapping('/v12');
0 ignored issues
show
Unused Code introduced by
$mapping is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
460
        $mapping = new RestMapping();
461
        $mapping->setMapping([
462
            new ClassMetadata(
463
                'carts',
464
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
465
                'mock\Mapado\RestClientSdk\EntityRepository'
466
            ),
467
            new ClassMetadata(
468
                'cart_items',
469
                'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
470
                'mock\Mapado\RestClientSdk\EntityRepository'
471
            ),
472
        ]);
473
474
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
475
        $this->calling($this->mockedSdk)->getMapping = $mapping;
476
477
        $this->calling($this->mockedRestClient)->get = [];
478
        $this->calling($this->mockedRestClient)->post = [];
479
480
        $cartItemRepository = new \mock\Mapado\RestClientSdk\EntityRepository(
481
            $this->mockedSdk,
482
            $this->mockedRestClient,
483
            $this->unitOfWork,
484
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'
485
        );
486
487
488
        $cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart;
489
        $cart->setId(1);
490
491
        $this
492
            ->if($cartItemRepository->find(1))
493
            ->then
494
                ->mock($this->mockedRestClient)
495
                    ->call('get')
496
                        ->withArguments('/cart_items/1')->once()
497
498
            ->if($cartItemRepository->findAll())
499
            ->then
500
                ->mock($this->mockedRestClient)
501
                    ->call('get')
502
                        ->withArguments('/cart_items')->once()
503
504
            ->if($cartItemRepository->findBy(['foo' => 'bar']))
505
            ->then
506
                ->mock($this->mockedRestClient)
507
                    ->call('get')
508
                        ->withArguments('/cart_items?foo=bar')->once()
509
510
            ->given($cartItem = new \mock\Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem)
511
            ->if($cartItemRepository->persist($cartItem))
512
            ->then
513
                ->mock($this->mockedRestClient)
514
                    ->call('post')
515
                        ->withArguments('/cart_items')->once()
516
        ;
517
    }
518
519
    public function testFindOneByWithHal()
520
    {
521
        $mapping = new RestMapping('v12');
522
        $classMetadata = new ClassMetadata(
523
            'orders',
524
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order',
525
            'mock\Mapado\RestClientSdk\EntityRepository'
526
        );
527
        $classMetadata->setAttributeList([
528
            new Attribute('@id', 'id', 'string', true),
529
        ]);
530
        $mapping->setMapping([$classMetadata]);
531
532
        $this->calling($this->mockedSdk)->getMapping = $mapping;
533
534
        $this->repository = new \mock\Mapado\RestClientSdk\EntityRepository(
535
            $this->mockedSdk,
536
            $this->mockedRestClient,
537
            $this->unitOfWork,
538
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'
539
        );
540
541
        $mapping->setConfig([
542
            'collectionKey' => 'fooList',
543
        ]);
544
        $this->calling($this->mockedRestClient)->get = [
545
            'fooList' => [
546
                [
547
                    '@id' => '/orders/2',
548
                ]
549
            ],
550
        ];
551
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
552
553
        $this
554
            ->then
555
                ->object($order = $this->repository->findOneBy(['a' => 'a']))
556
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Order')
557
                ->string($order->getId())
558
                    ->isEqualTo('/orders/2')
559
        ;
560
    }
561
562
    /**
563
     * testFindOneByWithoutResult
564
     *
565
     * @access public
566
     * @return void
567
     */
568
    public function testFindOneByWithoutResult()
569
    {
570
        $mapping = new RestMapping('v12');
571
        $classMetadata = new ClassMetadata(
572
            'orders',
573
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order',
574
            'mock\Mapado\RestClientSdk\EntityRepository'
575
        );
576
        $classMetadata->setAttributeList([
577
            new Attribute('@id', 'id', 'string', true),
578
        ]);
579
        $mapping->setMapping([$classMetadata]);
580
581
        $this->calling($this->mockedSdk)->getMapping = $mapping;
582
583
        $this->repository = new \mock\Mapado\RestClientSdk\EntityRepository(
584
            $this->mockedSdk,
585
            $this->mockedRestClient,
586
            $this->unitOfWork,
587
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'
588
        );
589
590
        $mapping->setConfig([
591
            'collectionKey' => 'fooList',
592
        ]);
593
        $this->calling($this->mockedRestClient)->get = [
594
            'fooList' => [
595
            ],
596
        ];
597
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
598
599
        $this
600
            ->then
601
                ->variable($order = $this->repository->findOneBy(['a' => 'a']))
602
                    ->isNull()
603
        ;
604
    }
605
606
    public function testUnitOfWork()
607
    {
608
        $ticket = (object) [
609
            'firstname' => 'foo',
610
            'lastname' => 'bar',
611
            'email' => '[email protected]',
612
        ];
613
        $this->unitOfWork->registerClean('@id1', $ticket);
614
        $this
615
            ->then
616
                ->variable($this->unitOfWork->getDirtyEntity('@id1'))
617
                    ->isEqualTo($ticket)
618
            ->then
619
                ->variable($this->unitOfWork->getDirtyData(
620
                    [
621
                        'ticketList' => [
622
                            [
623
                                '@id' => '/v12/tickets/1',
624
                                'firstname' => 'foo',
625
                                'lastname' => 'bar',
626
                                'email' => '[email protected]',
627
                                'order' => [
628
                                    'event' => [
629
                                        'contract' => [
630
                                            '@id' => '/v12/contracts/1',
631
                                            'name' => null,
632
                                        ],
633
                                    ],
634
                                ],
635
                            ],
636
                            [
637
                                '@id' => '/v12/tickets/2',
638
                                'firstname' => 'foo2',
639
                                'lastname' => 'bar2',
640
                                'email' => '[email protected]',
641
                            ],
642
                            [
643
                                '@id' => '/v12/tickets/3',
644
                                'firstname' => 'foo',
645
                                'lastname' => 'bar1',
646
                                'email' => '[email protected]',
647
                            ],
648
                        ],
649
                        'customerList' => [
650
                            '/v12/customers/1',
651
                            '/v12/customers/2',
652
                            '/v12/customers/3',
653
                        ],
654
                        'eventDateList' => [
655
                            [
656
                                '@id' => '/v12/event_dates/1',
657
                                'title' => 'foo',
658
                                'description' => 'bar',
659
                            ],
660
                            [
661
                                '@id' => '/v12/event_dates/2',
662
                                'title' => 'foo',
663
                                'description' => 'bar',
664
                            ],
665
                        ],
666
                        'tagList' => [
667
                            [
668
                                '@id' => '/v12/tags/1',
669
                                'title' => 'foo1',
670
                                'description' => 'bar',
671
                            ],
672
                            [
673
                                '@id' => '/v12/tags/2',
674
                                'title' => 'foo',
675
                                'description' => 'bar',
676
                            ],
677
                            [
678
                                '@id' => '/v12/tags/3',
679
                                'title' => 'foo',
680
                                'description' => 'bars',
681
                            ],
682
                        ],
683
                        'orderList' => [
684
                            [
685
                                '@id' => '/v12/orders/1',
686
                                'name' => 'order1',
687
                            ],
688
                        ],
689
                        'name' => 'foo',
690
                        'email' => '[email protected]',
691
                    ],
692
                    [
693
                        'ticketList' => [
694
                            [
695
                                '@id' => '/v12/tickets/1',
696
                                'firstname' => 'foo',
697
                                'lastname' => 'bar',
698
                                'email' => '[email protected]',
699
                                'order' => [
700
                                    'event' => [
701
                                        'contract' => [
702
                                            '@id' => '/v12/contracts/1',
703
                                            'name' => '/foo',
704
                                        ],
705
                                    ],
706
                                ],
707
                            ],
708
                            [
709
                                '@id' => '/v12/tickets/3',
710
                                'firstname' => 'foo',
711
                                'lastname' => 'bar',
712
                                'email' => '[email protected]',
713
                            ],
714
                        ],
715
                        'customerList' => [
716
                            '/v12/customers/1',
717
                            '/v12/customers/2',
718
                        ],
719
                        'eventDateList' => [
720
                            [
721
                                '@id' => '/v12/event_dates/1',
722
                                'title' => 'foo',
723
                                'description' => 'bar',
724
                            ],
725
                            [
726
                                '@id' => '/v12/event_dates/2',
727
                                'title' => 'foo',
728
                                'description' => 'bar',
729
                            ],
730
                        ],
731
                        'tagList' => [
732
                            [
733
                                '@id' => '/v12/tags/1',
734
                                'title' => 'foo',
735
                                'description' => 'bar',
736
                            ],
737
                            [
738
                                '@id' => '/v12/tags/2',
739
                                'title' => 'foo',
740
                                'description' => 'bar',
741
                            ],
742
                            [
743
                                '@id' => '/v12/tags/3',
744
                                'title' => 'foo',
745
                                'description' => 'bar',
746
                            ],
747
                        ],
748
                        'orderList' => [
749
                            [
750
                                '@id' => '/v12/orders/1',
751
                                'name' => 'order1',
752
                            ],
753
                            [
754
                                '@id' => '/v12/orders/2',
755
                                'name' => 'order2',
756
                            ],
757
                        ],
758
                        'name' => 'foo',
759
                        'email' => '[email protected]',
760
                    ]
761
                ))
762
                ->isEqualTo(
763
                    [
764
                        'ticketList' => [
765
                            [
766
                                'email' => '[email protected]',
767
                                'order' => [
768
                                    'event' => [
769
                                        'contract' => [
770
                                            'name' => null,
771
                                            '@id' => '/v12/contracts/1',
772
                                        ],
773
                                    ],
774
                                ],
775
                                '@id' => '/v12/tickets/1',
776
                            ],
777
                            [
778
                                '@id' => '/v12/tickets/2',
779
                                'firstname' => 'foo2',
780
                                'lastname' => 'bar2',
781
                                'email' => '[email protected]',
782
                            ],
783
                            [
784
                                '@id' => '/v12/tickets/3',
785
                                'firstname' => 'foo',
786
                                'lastname' => 'bar1',
787
                                'email' => '[email protected]',
788
                            ],
789
                        ],
790
                        'customerList' => [
791
                            '/v12/customers/1',
792
                            '/v12/customers/2',
793
                            '/v12/customers/3',
794
                        ],
795
                        'tagList' => [
796
                            [
797
                                'title' => 'foo1',
798
                                '@id' => '/v12/tags/1',
799
                            ],
800
                            [
801
                                '@id' => '/v12/tags/2',
802
                            ],
803
                            [
804
                                'description' => 'bars',
805
                                '@id' => '/v12/tags/3',
806
                            ],
807
                        ],
808
                        'orderList' => [
809
                            [
810
                                '@id' => '/v12/orders/1',
811
                            ],
812
                        ],
813
                        'email' => '[email protected]',
814
                    ]
815
                )
816
        ;
817
    }
818
}
819