GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#62)
by Simone
02:35
created

testBuildRightPathAlsoWithMoreDifferentParentsIntPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 30

Duplication

Lines 50
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 30
nc 1
nop 0
dl 50
loc 50
rs 9.3333
c 0
b 0
f 0
1
<?php
2
3
use Mado\QueryBundle\Component\Meta\JsonPathFinder;
4
use PHPUnit\Framework\TestCase as TestCase;
5
6
class JsonPathFinderTest extends TestCase
7
{
8
    private $samepleJson;
9
10 View Code Duplication
    public function testFirdstChildOfAnEntity()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
    {
12
        $this->samepleJson = [
13
            "AppBundle\\Entity\\Bar" => [
14
                "relations" => [
15
                    "fizz" => "AppBundle\\Entity\\Fizz",
16
                ]
17
            ],
18
        ];
19
20
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
22
            ->disableOriginalConstructor()
23
            ->getMock();
24
25
        $this->mapper->expects($this->once())
26
            ->method('getMap')
27
            ->will($this->returnValue(
28
                $this->samepleJson
29
            ));
30
31
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
            $this->mapper
33
        );
34
35
        $this->assertEquals(
36
            "AppBundle\\Entity\\Fizz",
37
            $this->pathFinder->getFirstChildOf("AppBundle\\Entity\\Bar")
38
        );
39
    }
40
41 View Code Duplication
    public function testGetFirstEntityThatPointDirectlyToAnEntity()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $this->samepleJson = [
44
            "AppBundle\\Entity\\Bar" => [
45
                "relations" => [
46
                    "fizz" => "AppBundle\\Entity\\Fizz",
47
                ]
48
            ],
49
        ];
50
51
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
52
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
53
            ->disableOriginalConstructor()
54
            ->getMock();
55
56
        $this->mapper->expects($this->once())
57
            ->method('getMap')
58
            ->will($this->returnValue(
59
                $this->samepleJson
60
            ));
61
62
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
63
            $this->mapper
64
        );
65
66
        $this->assertEquals(
67
            "AppBundle\\Entity\\Bar",
68
            $this->pathFinder->getFirstParentOf("AppBundle\\Entity\\Fizz")
69
        );
70
    }
71
72 View Code Duplication
    public function testGetRelationNameThatPointToAnEntity()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $this->samepleJson = [
75
            "AppBundle\\Entity\\Bar" => [
76
                "relations" => [
77
                    "fizz" => "AppBundle\\Entity\\Fizz",
78
                ]
79
            ],
80
        ];
81
82
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
83
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
84
            ->disableOriginalConstructor()
85
            ->getMock();
86
87
        $this->mapper->expects($this->once())
88
            ->method('getMap')
89
            ->will($this->returnValue(
90
                $this->samepleJson
91
            ));
92
93
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
94
            $this->mapper
95
        );
96
97
        $this->assertEquals(
98
            "fizz",
99
            $this->pathFinder->getSourceRelation("AppBundle\\Entity\\Fizz")
100
        );
101
    }
102
103 View Code Duplication
    public function testPathFromEntityToDestination()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        $this->samepleJson = [
106
            "AppBundle\\Entity\\Root" => [
107
                "relations" => [
108
                    "foo" => "AppBundle\\Entity\\Foo",
109
                ]
110
            ],
111
            "AppBundle\\Entity\\Foo" => [
112
                "relations" => [
113
                    "bar" => "AppBundle\\Entity\\Bar",
114
                ]
115
            ],
116
            "AppBundle\\Entity\\Bar" => [
117
                "relations" => [
118
                    "fizz" => "AppBundle\\Entity\\Fizz",
119
                ]
120
            ],
121
        ];
122
123
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
124
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
125
            ->disableOriginalConstructor()
126
            ->getMock();
127
128
        $this->mapper->expects($this->once())
129
            ->method('getMap')
130
            ->will($this->returnValue(
131
                $this->samepleJson
132
            ));
133
134
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
135
            $this->mapper
136
        );
137
138
        $this->pathFinder->setEntity("AppBundle\\Entity\\Root");
139
140
        $this->assertEquals(
141
            "foo.bar.fizz",
142
            $this->pathFinder->getPathTo("AppBundle\\Entity\\Fizz")
143
        );
144
    }
145
146 View Code Duplication
    public function testBuildPathBetweenTwoEntities()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    {
148
        $this->samepleJson = [
149
            "GammaBundle\\Entity\\Item" => [
150
                "relations" => [
151
                    "items" => "AppBundle\\Entity\\Foo",
152
                ]
153
            ],
154
            "AppBundle\\Entity\\Foo" => [
155
                "relations" => [
156
                    "item" => "ZarroBundle\\Entity\\Item",
157
                ]
158
            ],
159
            "ZarroBundle\\Entity\\Item" => [
160
                "relations" => [
161
                    "family" => "AppBundle\\Entity\\Family",
162
                ]
163
            ],
164
        ];
165
166
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
167
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
168
            ->disableOriginalConstructor()
169
            ->getMock();
170
171
        $this->mapper->expects($this->once())
172
            ->method('getMap')
173
            ->will($this->returnValue(
174
                $this->samepleJson
175
            ));
176
177
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
178
            $this->mapper
179
        );
180
181
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
182
183
        $this->assertEquals(
184
            "_embedded.items.item.family",
185
            $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family")
186
        );
187
    }
188
189
    /**
190
     * @expectedException \RuntimeException
191
     */
192
    public function testCantBuildPathIfNotExists()
193
    {
194
        $this->samepleJson = [
195
            "GammaBundle\\Entity\\Merenghe" => [
196
                "relations" => [
197
                    "items" => "AppBundle\\Entity\\Foo",
198
                ]
199
            ],
200
            "AppBundle\\Entity\\Foo" => [
201
                "relations" => [
202
                    "item" => "ZarroBundle\\Entity\\Item",
203
                ]
204
            ],
205
            "ZarroBundle\\Entity\\Item" => [
206
                "relations" => [
207
                    "family" => "AppBundle\\Entity\\Family",
208
                ]
209
            ],
210
        ];
211
212
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
213
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
214
            ->disableOriginalConstructor()
215
            ->getMock();
216
217
        $this->mapper->expects($this->once())
218
            ->method('getMap')
219
            ->will($this->returnValue(
220
                $this->samepleJson
221
            ));
222
223
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
224
            $this->mapper
225
        );
226
227
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
228
        $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family");
229
    }
230
231 View Code Duplication
    public function testCountNumberOfParentWithDestinationPath()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
232
    {
233
        $this->samepleJson = [
234
            "GammaBundle\\Entity\\Zzz" => [
235
                "relations" => [
236
                    "items" => "AppBundle\\Entity\\Foo",
237
                ]
238
            ],
239
            "GammaBundle\\Entity\\Item" => [
240
                "relations" => [
241
                    "items" => "AppBundle\\Entity\\Foo",
242
                ]
243
            ],
244
        ];
245
246
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
247
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
248
            ->disableOriginalConstructor()
249
            ->getMock();
250
251
        $this->mapper->expects($this->once())
252
            ->method('getMap')
253
            ->will($this->returnValue(
254
                $this->samepleJson
255
            ));
256
257
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
258
            $this->mapper
259
        );
260
261
        $this->assertEquals(
262
            2,
263
            $this->pathFinder->numberOfRealtionTo("AppBundle\\Entity\\Foo")
264
        );
265
    }
266
267 View Code Duplication
    public function testListParentOfEntity()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
    {
269
        $this->samepleJson = [
270
            "GammaBundle\\Entity\\Zzz" => [
271
                "relations" => [
272
                    "items" => "AppBundle\\Entity\\Foo",
273
                ]
274
            ],
275
            "GammaBundle\\Entity\\Item" => [
276
                "relations" => [
277
                    "items" => "AppBundle\\Entity\\Foo",
278
                ]
279
            ],
280
        ];
281
282
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
283
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
284
            ->disableOriginalConstructor()
285
            ->getMock();
286
287
        $this->mapper->expects($this->once())
288
            ->method('getMap')
289
            ->will($this->returnValue(
290
                $this->samepleJson
291
            ));
292
293
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
294
            $this->mapper
295
        );
296
297
        $this->assertEquals(
298
            [
299
                "GammaBundle\\Entity\\Zzz",
300
                "GammaBundle\\Entity\\Item",
301
            ],
302
            $this->pathFinder->listOfParentsOf("AppBundle\\Entity\\Foo")
303
        );
304
    }
305
306
    public function testBuildRightPathAlsoWithMoreDifferentParentsAtTheEnd()
307
    {
308
        $this->samepleJson = [
309
            "GammaBundle\\Entity\\Zzz" => [
310
                "relations" => [
311
                    "items" => "AppBundle\\Entity\\Foo",
312
                ]
313
            ],
314
            "GammaBundle\\Entity\\Item" => [
315
                "relations" => [
316
                    "items" => "AppBundle\\Entity\\Foo",
317
                ]
318
            ],
319
            "AppBundle\\Entity\\Foo" => [
320
                "relations" => [
321
                    "item" => "ZarroBundle\\Entity\\Item",
322
                ]
323
            ],
324
            "ZarroBundle\\Entity\\Item" => [
325
                "relations" => [
326
                    "family" => "AppBundle\\Entity\\Family",
327
                ]
328
            ],
329
        ];
330
331
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
332
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
333
            ->disableOriginalConstructor()
334
            ->getMock();
335
336
        $this->mapper->expects($this->once())
337
            ->method('getMap')
338
            ->will($this->returnValue(
339
                $this->samepleJson
340
            ));
341
342
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
343
            $this->mapper
344
        );
345
346
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
347
348
        $this->assertEquals(
349
            "_embedded.items.item.family",
350
            $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family")
351
        );
352
353
        $this->assertEquals(
354
            [
355
                "AppBundle\\Entity\\Family",
356
                "ZarroBundle\\Entity\\Item",
357
                "AppBundle\\Entity\\Foo",
358
            ],
359
            $this->pathFinder->getEntitiesPath("AppBundle\\Entity\\Family")
0 ignored issues
show
Unused Code introduced by
The call to Mado\QueryBundle\Compone...nder::getEntitiesPath() has too many arguments starting with 'AppBundle\Entity\Family'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

359
            $this->pathFinder->/** @scrutinizer ignore-call */ 
360
                               getEntitiesPath("AppBundle\\Entity\\Family")

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
360
        );
361
    }
362
363 View Code Duplication
    public function testFoo()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
364
    {
365
        $this->samepleJson = [
366
            "GammaBundle\\Entity\\Zzz" => [
367
                "relations" => [
368
                    "items" => "AppBundle\\Entity\\Foo",
369
                ]
370
            ],
371
            "GammaBundle\\Entity\\Item" => [
372
                "relations" => [
373
                    "items" => "AppBundle\\Entity\\Foo",
374
                ]
375
            ],
376
            "AppBundle\\Entity\\Foo" => [
377
                "relations" => [
378
                    "item" => "ZarroBundle\\Entity\\Item",
379
                ]
380
            ],
381
            "ZarroBundle\\Entity\\Item" => [
382
                "relations" => [
383
                    "family" => "AppBundle\\Entity\\Family",
384
                ]
385
            ],
386
        ];
387
388
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
389
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
390
            ->disableOriginalConstructor()
391
            ->getMock();
392
393
        $this->mapper->expects($this->once())
394
            ->method('getMap')
395
            ->will($this->returnValue(
396
                $this->samepleJson
397
            ));
398
399
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
400
            $this->mapper
401
        );
402
403
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
404
405
        $this->assertEquals(
406
            "_embedded.items.item.family",
407
            $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family")
408
        );
409
    }
410
411 View Code Duplication
    public function testBuildRightPathAlsoWithMoreDifferentParentsIntPath()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
412
    {
413
        $this->samepleJson = [
414
            "GammaBundle\\Entity\\Item" => [
415
                "relations" => [
416
                    "items" => "AppBundle\\Entity\\Foo",
417
                ]
418
            ],
419
            "AppBundle\\Entity\\Wrong" => [
420
                "relations" => [
421
                    "item" => "ZarroBundle\\Entity\\Item",
422
                ]
423
            ],
424
            "AppBundle\\Entity\\Foo" => [
425
                "relations" => [
426
                    "item" => "ZarroBundle\\Entity\\Item",
427
                ]
428
            ],
429
            "ZarroBundle\\Entity\\Item" => [
430
                "relations" => [
431
                    "family" => "AppBundle\\Entity\\Family",
432
                ]
433
            ],
434
        ];
435
436
        $this->mapper = $this
0 ignored issues
show
Bug Best Practice introduced by
The property mapper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
437
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
438
            ->disableOriginalConstructor()
439
            ->getMock();
440
441
        $this->mapper->expects($this->once())
442
            ->method('getMap')
443
            ->will($this->returnValue(
444
                $this->samepleJson
445
            ));
446
447
        $this->pathFinder = new JsonPathFinder(
0 ignored issues
show
Bug Best Practice introduced by
The property pathFinder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
448
            $this->mapper
449
        );
450
451
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
452
453
        $this->pathFinder->skipStep(
454
            "AppBundle\\Entity\\Wrong",
455
            "ZarroBundle\\Entity\\Item"
456
        );
457
458
        $this->assertEquals(
459
            "_embedded.items.item.family",
460
            $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family")
461
        );
462
    }
463
}
464