Completed
Pull Request — master (#61)
by
unknown
01:37
created

EntityRepository::testPutWithoutStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 48
rs 9.125
cc 1
eloc 33
nc 1
nop 0
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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Mapado\RestClientSdk\Tests\Units\UnitOfWork.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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
46
        $this->mapping = new RestMapping('v12');
47
        $this->mapping->setMapping([
48
            new ClassMetadata(
49
                'orders',
50
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Model',
51
                'mock\Mapado\RestClientSdk\EntityRepository'
52
            ),
53
        ]);
54
        $this->unitOfWork = new UnitOfWork($this->mapping);
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 testPutWithoutStore()
321
    {
322
        $mapping = new RestMapping('/v12');
323
        $mapping->setMapping([
324
            new ClassMetadata(
325
                'products',
326
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Product',
327
                'mock\Mapado\RestClientSdk\EntityRepository'
328
            ),
329
        ]);
330
331
        $this->calling($this->mockedSdk)->getMapping = $mapping;
332
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
333
334
335
        $product1 = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Product;
336
        $product1->setId('/v12/products/1');
337
338
        $this->calling($this->mockedHydrator)->hydrate = $product1;
339
        $this->calling($this->mockedHydrator)->hydrateList = [$product1];
340
341
        $arrayAdapter = new ArrayAdapter(0, false);
342
        $this->calling($this->mockedSdk)->getCacheItemPool = $arrayAdapter;
343
        $this->calling($this->mockedSdk)->getCachePrefix = 'test_prefix_';
344
345
        $this->calling($this->mockedRestClient)->get = $product1;
346
        $this->calling($this->mockedRestClient)->put = $product1;
347
        $this->calling($this->mockedRestClient)->delete = null;
348
349
        $repository = new \mock\Mapado\RestClientSdk\EntityRepository(
350
            $this->mockedSdk,
351
            $this->mockedRestClient,
352
            $this->unitOfWork,
353
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Product'
354
        );
355
356
        $this
357
            ->if($repository->find(1))
358
            ->then
359
                ->mock($this->mockedRestClient)
360
                    ->call('get')
361
                        ->withArguments('/v12/products/1')->once();
362
363
        $this->unitOfWork->clear('/v12/products/1');
364
        $this
365
            // after update
366
            ->if($repository->update($product1));
367
    }
368
369
    public function testCacheWithIriAsId()
370
    {
371
        $annotationDriver = new AnnotationDriver(__DIR__ . '/../cache/');
372
        $mapping = new RestMapping();
373
        $mapping->setMapping($annotationDriver->loadDirectory(__DIR__ . '/../Model/Issue46/'));
374
375
        $unitOfWork = new UnitOfWork($mapping);
376
377
        $this->calling($this->mockedSdk)->getMapping = $mapping;
378
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $unitOfWork);
379
380
        $section1 = new \Mapado\RestClientSdk\Tests\Model\Issue46\Section;
381
        $section1->setIri('/sections/1');
382
383
        $this->calling($this->mockedHydrator)->hydrate = $section1;
384
        $this->calling($this->mockedHydrator)->hydrateList = [$section1];
385
386
        $arrayAdapter = new ArrayAdapter(0, false);
387
        $this->calling($this->mockedSdk)->getCacheItemPool = $arrayAdapter;
388
        $this->calling($this->mockedSdk)->getCachePrefix = 'test_prefix_';
389
390
        $this->calling($this->mockedRestClient)->get = $section1;
391
        $this->calling($this->mockedRestClient)->put = $section1;
392
        $this->calling($this->mockedRestClient)->delete = null;
393
394
        $repository = new \mock\Mapado\RestClientSdk\EntityRepository(
395
            $this->mockedSdk,
396
            $this->mockedRestClient,
397
            $unitOfWork,
398
            'Mapado\RestClientSdk\Tests\Model\Issue46\Section'
399
        );
400
401
        $this
402
            ->if($repository->findBy(['section' => $section1]))
403
           ->then
404
               ->mock($this->mockedRestClient)
405
                   ->call('get')
406
                       ->withArguments('/sections?section=%2Fsections%2F1')->once()
407
408
            ->if($repository->findAll())
409
            ->then
410
                ->boolean($arrayAdapter->hasItem('test_prefix__sections_1'))
411
                    ->isTrue()
412
413
           ->if($repository->find(1))
414
           ->then
415
               ->mock($this->mockedRestClient)
416
                   ->call('get')
417
                       ->withArguments('/sections/1')->never()
418
419
            // after update
420
            ->if($repository->update($section1))
421
                ->boolean($arrayAdapter->hasItem('test_prefix__sections_1'))
422
                    ->isFalse()
423
            ->then
424
                ->mock($this->mockedRestClient)
425
                    ->call('put')
426
                        ->withArguments('/sections/1')->once()
427
428
            ->if($repository->find(1))
429
            ->then
430
                ->mock($this->mockedRestClient)
431
                    ->call('get')
432
                        ->withArguments('/sections/1')->once()
433
434
            // after deletion
435
            ->if($repository->remove($section1))
436
            ->then
437
                ->boolean($arrayAdapter->hasItem('test_prefix__sections_1'))
438
                    ->isFalse()
439
        ;
440
    }
441
442
    /**
443
     * testFindNotFound
444
     *
445
     * @access public
446
     * @return void
447
     */
448
    public function testFindNotFound()
449
    {
450
        $this->calling($this->mockedRestClient)->get = null;
451
452
        $this
453
            ->variable($this->repository->find('1'))
454
            ->isNull()
455
        ;
456
    }
457
458
    public function testFindOneByObject()
459
    {
460
        $mapping = new RestMapping('v12');
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)->getMapping = $mapping;
475
476
        $this->calling($this->mockedRestClient)->get = [];
477
478
        $cartItemRepository = new \mock\Mapado\RestClientSdk\EntityRepository(
479
            $this->mockedSdk,
480
            $this->mockedRestClient,
481
            $this->unitOfWork,
482
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'
483
        );
484
485
486
        $cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart;
487
        $cart->setId(1);
488
489
        $this
490
            ->given($cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart)
491
                ->and($cart->setId(1))
492
            ->if($cartItemRepository->findOneByCart($cart))
493
            ->then
494
                ->mock($this->mockedRestClient)
495
                    ->call('get')
496
                        ->withArguments('v12/cart_items?cart=1')->once()
497
498
            // test with unmapped class
499
            ->given($cart = new \mock\stdClass)
500
            ->if($cartItemRepository->findOneByCart($cart))
501
            ->then
502
                ->mock($this->mockedRestClient)
503
                    ->call('get')
504
                        ->withArguments('v12/cart_items?')->once()
505
        ;
506
    }
507
508
    public function testWithoutMappingPrefix()
509
    {
510
        $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...
511
        $mapping = new RestMapping();
512
        $mapping->setMapping([
513
            new ClassMetadata(
514
                'carts',
515
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Cart',
516
                'mock\Mapado\RestClientSdk\EntityRepository'
517
            ),
518
            new ClassMetadata(
519
                'cart_items',
520
                'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem',
521
                'mock\Mapado\RestClientSdk\EntityRepository'
522
            ),
523
        ]);
524
525
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
526
        $this->calling($this->mockedSdk)->getMapping = $mapping;
527
528
        $this->calling($this->mockedRestClient)->get = [];
529
        $this->calling($this->mockedRestClient)->post = [];
530
531
        $cartItemRepository = new \mock\Mapado\RestClientSdk\EntityRepository(
532
            $this->mockedSdk,
533
            $this->mockedRestClient,
534
            $this->unitOfWork,
535
            'Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem'
536
        );
537
538
539
        $cart = new \Mapado\RestClientSdk\Tests\Model\JsonLd\Cart;
540
        $cart->setId(1);
541
542
        $this
543
            ->if($cartItemRepository->find(1))
544
            ->then
545
                ->mock($this->mockedRestClient)
546
                    ->call('get')
547
                        ->withArguments('/cart_items/1')->once()
548
549
            ->if($cartItemRepository->findAll())
550
            ->then
551
                ->mock($this->mockedRestClient)
552
                    ->call('get')
553
                        ->withArguments('/cart_items')->once()
554
555
            ->if($cartItemRepository->findBy(['foo' => 'bar']))
556
            ->then
557
                ->mock($this->mockedRestClient)
558
                    ->call('get')
559
                        ->withArguments('/cart_items?foo=bar')->once()
560
561
            ->given($cartItem = new \mock\Mapado\RestClientSdk\Tests\Model\JsonLd\CartItem)
562
            ->if($cartItemRepository->persist($cartItem))
563
            ->then
564
                ->mock($this->mockedRestClient)
565
                    ->call('post')
566
                        ->withArguments('/cart_items')->once()
567
        ;
568
    }
569
570
    public function testFindOneByWithHal()
571
    {
572
        $mapping = new RestMapping('v12');
573
        $classMetadata = new ClassMetadata(
574
            'orders',
575
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order',
576
            'mock\Mapado\RestClientSdk\EntityRepository'
577
        );
578
        $classMetadata->setAttributeList([
579
            new Attribute('@id', 'id', 'string', true),
580
        ]);
581
        $mapping->setMapping([$classMetadata]);
582
583
        $this->calling($this->mockedSdk)->getMapping = $mapping;
584
585
        $this->repository = new \mock\Mapado\RestClientSdk\EntityRepository(
586
            $this->mockedSdk,
587
            $this->mockedRestClient,
588
            $this->unitOfWork,
589
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'
590
        );
591
592
        $mapping->setConfig([
593
            'collectionKey' => 'fooList',
594
        ]);
595
        $this->calling($this->mockedRestClient)->get = [
596
            'fooList' => [
597
                [
598
                    '@id' => '/orders/2',
599
                ]
600
            ],
601
        ];
602
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
603
604
        $this
605
            ->then
606
                ->object($order = $this->repository->findOneBy(['a' => 'a']))
607
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\Order')
608
                ->string($order->getId())
609
                    ->isEqualTo('/orders/2')
610
        ;
611
    }
612
613
    /**
614
     * testFindOneByWithoutResult
615
     *
616
     * @access public
617
     * @return void
618
     */
619
    public function testFindOneByWithoutResult()
620
    {
621
        $mapping = new RestMapping('v12');
622
        $classMetadata = new ClassMetadata(
623
            'orders',
624
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order',
625
            'mock\Mapado\RestClientSdk\EntityRepository'
626
        );
627
        $classMetadata->setAttributeList([
628
            new Attribute('@id', 'id', 'string', true),
629
        ]);
630
        $mapping->setMapping([$classMetadata]);
631
632
        $this->calling($this->mockedSdk)->getMapping = $mapping;
633
634
        $this->repository = new \mock\Mapado\RestClientSdk\EntityRepository(
635
            $this->mockedSdk,
636
            $this->mockedRestClient,
637
            $this->unitOfWork,
638
            'Mapado\RestClientSdk\Tests\Model\JsonLd\Order'
639
        );
640
641
        $mapping->setConfig([
642
            'collectionKey' => 'fooList',
643
        ]);
644
        $this->calling($this->mockedRestClient)->get = [
645
            'fooList' => [
646
            ],
647
        ];
648
        $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping, $this->unitOfWork);
649
650
        $this
651
            ->then
652
                ->variable($order = $this->repository->findOneBy(['a' => 'a']))
653
                    ->isNull()
654
        ;
655
    }
656
}
657