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

EntityRepository::testPutWithoutStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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