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:45
created

testBuildPathBetweenTwoEntities()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 24

Duplication

Lines 40
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 24
nc 1
nop 0
dl 40
loc 40
rs 8.8571
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 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...
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\\Bar",
37
            $this->pathFinder->getFirstParentOf("AppBundle\\Entity\\Fizz")
38
        );
39
    }
40
41 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...
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
            "fizz",
68
            $this->pathFinder->getSourceRelation("AppBundle\\Entity\\Fizz")
69
        );
70
    }
71
72 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...
73
    {
74
        $this->samepleJson = [
75
            "AppBundle\\Entity\\Root" => [
76
                "relations" => [
77
                    "foo" => "AppBundle\\Entity\\Foo",
78
                ]
79
            ],
80
            "AppBundle\\Entity\\Foo" => [
81
                "relations" => [
82
                    "bar" => "AppBundle\\Entity\\Bar",
83
                ]
84
            ],
85
            "AppBundle\\Entity\\Bar" => [
86
                "relations" => [
87
                    "fizz" => "AppBundle\\Entity\\Fizz",
88
                ]
89
            ],
90
        ];
91
92
        $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...
93
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
94
            ->disableOriginalConstructor()
95
            ->getMock();
96
97
        $this->mapper->expects($this->once())
98
            ->method('getMap')
99
            ->will($this->returnValue(
100
                $this->samepleJson
101
            ));
102
103
        $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...
104
            $this->mapper
105
        );
106
107
        $this->pathFinder->setEntity("AppBundle\\Entity\\Root");
108
109
        $this->assertEquals(
110
            "foo.bar.fizz",
111
            $this->pathFinder->getPathTo("AppBundle\\Entity\\Fizz")
112
        );
113
    }
114
115 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...
116
    {
117
        $this->samepleJson = [
118
            "GammaBundle\\Entity\\Item" => [
119
                "relations" => [
120
                    "items" => "AppBundle\\Entity\\Foo",
121
                ]
122
            ],
123
            "AppBundle\\Entity\\Foo" => [
124
                "relations" => [
125
                    "item" => "ZarroBundle\\Entity\\Item",
126
                ]
127
            ],
128
            "ZarroBundle\\Entity\\Item" => [
129
                "relations" => [
130
                    "family" => "AppBundle\\Entity\\Family",
131
                ]
132
            ],
133
        ];
134
135
        $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...
136
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
137
            ->disableOriginalConstructor()
138
            ->getMock();
139
140
        $this->mapper->expects($this->once())
141
            ->method('getMap')
142
            ->will($this->returnValue(
143
                $this->samepleJson
144
            ));
145
146
        $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...
147
            $this->mapper
148
        );
149
150
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
151
152
        $this->assertEquals(
153
            "_embedded.items.item.family",
154
            $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family")
155
        );
156
    }
157
158
    /**
159
     * @expectedException \RuntimeException
160
     */
161
    public function testCantBuildPathIfNotExists()
162
    {
163
        $this->samepleJson = [
164
            "GammaBundle\\Entity\\Merenghe" => [
165
                "relations" => [
166
                    "items" => "AppBundle\\Entity\\Foo",
167
                ]
168
            ],
169
            "AppBundle\\Entity\\Foo" => [
170
                "relations" => [
171
                    "item" => "ZarroBundle\\Entity\\Item",
172
                ]
173
            ],
174
            "ZarroBundle\\Entity\\Item" => [
175
                "relations" => [
176
                    "family" => "AppBundle\\Entity\\Family",
177
                ]
178
            ],
179
        ];
180
181
        $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...
182
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
183
            ->disableOriginalConstructor()
184
            ->getMock();
185
186
        $this->mapper->expects($this->once())
187
            ->method('getMap')
188
            ->will($this->returnValue(
189
                $this->samepleJson
190
            ));
191
192
        $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...
193
            $this->mapper
194
        );
195
196
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
197
        $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family");
198
    }
199
200 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...
201
    {
202
        $this->samepleJson = [
203
            "GammaBundle\\Entity\\Zzz" => [
204
                "relations" => [
205
                    "items" => "AppBundle\\Entity\\Foo",
206
                ]
207
            ],
208
            "GammaBundle\\Entity\\Item" => [
209
                "relations" => [
210
                    "items" => "AppBundle\\Entity\\Foo",
211
                ]
212
            ],
213
        ];
214
215
        $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...
216
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
217
            ->disableOriginalConstructor()
218
            ->getMock();
219
220
        $this->mapper->expects($this->once())
221
            ->method('getMap')
222
            ->will($this->returnValue(
223
                $this->samepleJson
224
            ));
225
226
        $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...
227
            $this->mapper
228
        );
229
230
        $this->assertEquals(
231
            2,
232
            $this->pathFinder->numberOfRealtionTo("AppBundle\\Entity\\Foo")
233
        );
234
    }
235
236 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...
237
    {
238
        $this->samepleJson = [
239
            "GammaBundle\\Entity\\Zzz" => [
240
                "relations" => [
241
                    "items" => "AppBundle\\Entity\\Foo",
242
                ]
243
            ],
244
            "GammaBundle\\Entity\\Item" => [
245
                "relations" => [
246
                    "items" => "AppBundle\\Entity\\Foo",
247
                ]
248
            ],
249
        ];
250
251
        $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...
252
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
253
            ->disableOriginalConstructor()
254
            ->getMock();
255
256
        $this->mapper->expects($this->once())
257
            ->method('getMap')
258
            ->will($this->returnValue(
259
                $this->samepleJson
260
            ));
261
262
        $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...
263
            $this->mapper
264
        );
265
266
        $this->assertEquals(
267
            [
268
                "GammaBundle\\Entity\\Zzz",
269
                "GammaBundle\\Entity\\Item",
270
            ],
271
            $this->pathFinder->listOfParentsOf("AppBundle\\Entity\\Foo")
272
        );
273
    }
274
275
    public function testBuildRightPathAlsoWithMoreDifferentParentsAtTheEnd()
276
    {
277
        $this->samepleJson = [
278
            "GammaBundle\\Entity\\Zzz" => [
279
                "relations" => [
280
                    "items" => "AppBundle\\Entity\\Foo",
281
                ]
282
            ],
283
            "GammaBundle\\Entity\\Item" => [
284
                "relations" => [
285
                    "items" => "AppBundle\\Entity\\Foo",
286
                ]
287
            ],
288
            "AppBundle\\Entity\\Foo" => [
289
                "relations" => [
290
                    "item" => "ZarroBundle\\Entity\\Item",
291
                ]
292
            ],
293
            "ZarroBundle\\Entity\\Item" => [
294
                "relations" => [
295
                    "family" => "AppBundle\\Entity\\Family",
296
                ]
297
            ],
298
        ];
299
300
        $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...
301
            ->getMockBuilder('Mado\QueryBundle\Component\Meta\RelationDatamapper')
302
            ->disableOriginalConstructor()
303
            ->getMock();
304
305
        $this->mapper->expects($this->once())
306
            ->method('getMap')
307
            ->will($this->returnValue(
308
                $this->samepleJson
309
            ));
310
311
        $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...
312
            $this->mapper
313
        );
314
315
        $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
316
317
        $this->assertEquals(
318
            "_embedded.items.item.family",
319
            $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family")
320
        );
321
    }
322
323
    // public function testBuildRightPathAlsoWithMoreDifferentParentsIntPath()
324
    // {
325
    //     $this->markTestSkipped('sono troppo stanco');
326
327
    //     $this->samepleJson = [
328
    //         "GammaBundle\\Entity\\Zzz" => [
329
    //             "relations" => [
330
    //                 "items" => "AppBundle\\Entity\\Foo",
331
    //             ]
332
    //         ],
333
    //         "GammaBundle\\Entity\\Item" => [
334
    //             "relations" => [
335
    //                 "items" => "AppBundle\\Entity\\Foo",
336
    //             ]
337
    //         ],
338
    //         "AppBundle\\Entity\\Wrong" => [
339
    //             "relations" => [
340
    //                 "item" => "ZarroBundle\\Entity\\Item",
341
    //             ]
342
    //         ],
343
    //         "AppBundle\\Entity\\Foo" => [
344
    //             "relations" => [
345
    //                 "item" => "ZarroBundle\\Entity\\Item",
346
    //             ]
347
    //         ],
348
    //         "ZarroBundle\\Entity\\Item" => [
349
    //             "relations" => [
350
    //                 "family" => "AppBundle\\Entity\\Family",
351
    //             ]
352
    //         ],
353
    //     ];
354
355
    //     $this->mapper = $this
356
    //         ->getMockBuilder('RelationDatamapper')
357
    //         ->disableOriginalConstructor()
358
    //         ->getMock();
359
360
    //     $this->mapper->expects($this->once())
361
    //         ->method('getMap')
362
    //         ->will($this->returnValue(
363
    //             $this->samepleJson
364
    //         ));
365
366
    //     $this->pathFinder = new JsonPathFinder(
367
    //         $this->mapper
368
    //     );
369
370
    //     $this->pathFinder->setQueryStartEntity("GammaBundle\\Entity\\Item");
371
372
    //     $this->assertEquals(
373
    //         "_embedded.items.item.family",
374
    //         $this->pathFinder->getPathToEntity("AppBundle\\Entity\\Family")
375
    //     );
376
    // }
377
}
378