1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Lug package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Lug\Bundle\ResourceBundle\Tests\Routing; |
13
|
|
|
|
14
|
|
|
use Lug\Bundle\ResourceBundle\Routing\ParameterResolver; |
15
|
|
|
use Lug\Component\Resource\Model\ResourceInterface; |
16
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
18
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
19
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author GeLo <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ParameterResolverTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ParameterResolver |
28
|
|
|
*/ |
29
|
|
|
private $parameterResolver; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|RequestStack |
33
|
|
|
*/ |
34
|
|
|
private $requestStack; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface |
38
|
|
|
*/ |
39
|
|
|
private $propertyAccessor; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected function setUp() |
45
|
|
|
{ |
46
|
|
|
$this->requestStack = $this->createRequestStackMock(); |
47
|
|
|
$this->propertyAccessor = $this->createPropertyAccessorMock(); |
48
|
|
|
|
49
|
|
|
$this->parameterResolver = new ParameterResolver($this->requestStack, $this->propertyAccessor); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testResolveApiWithoutRequest() |
53
|
|
|
{ |
54
|
|
|
$this->assertFalse($this->parameterResolver->resolveApi()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testResolveApiWihApiRequest() |
58
|
|
|
{ |
59
|
|
|
$this->requestStack |
|
|
|
|
60
|
|
|
->expects($this->exactly(2)) |
61
|
|
|
->method('getMasterRequest') |
62
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
63
|
|
|
|
64
|
|
|
$request->attributes |
65
|
|
|
->expects($this->once()) |
66
|
|
|
->method('get') |
67
|
|
|
->with($this->identicalTo('_lug_api'), $this->identicalTo(false)) |
68
|
|
|
->will($this->returnValue(true)); |
69
|
|
|
|
70
|
|
|
$this->assertTrue($this->parameterResolver->resolveApi()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
public function testResolveApiWithHtmlRequest() |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$this->requestStack |
|
|
|
|
76
|
|
|
->expects($this->exactly(2)) |
77
|
|
|
->method('getMasterRequest') |
78
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
79
|
|
|
|
80
|
|
|
$request |
|
|
|
|
81
|
|
|
->expects($this->once()) |
82
|
|
|
->method('getRequestFormat') |
83
|
|
|
->will($this->returnValue('html')); |
84
|
|
|
|
85
|
|
|
$this->assertFalse($this->parameterResolver->resolveApi()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
View Code Duplication |
public function testResolveApiWithCustomRequest() |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
$this->requestStack |
|
|
|
|
91
|
|
|
->expects($this->exactly(2)) |
92
|
|
|
->method('getMasterRequest') |
93
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
94
|
|
|
|
95
|
|
|
$request |
|
|
|
|
96
|
|
|
->expects($this->once()) |
97
|
|
|
->method('getRequestFormat') |
98
|
|
|
->will($this->returnValue('json')); |
99
|
|
|
|
100
|
|
|
$this->assertTrue($this->parameterResolver->resolveApi()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testResolveCriteriaWithoutRequest() |
104
|
|
|
{ |
105
|
|
|
$this->assertEmpty($this->parameterResolver->resolveCriteria()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
View Code Duplication |
public function testResolveCriteriaWithDefault() |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
$this->requestStack |
|
|
|
|
111
|
|
|
->expects($this->exactly(2)) |
112
|
|
|
->method('getMasterRequest') |
113
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
114
|
|
|
|
115
|
|
|
$request->attributes |
116
|
|
|
->expects($this->once()) |
117
|
|
|
->method('get') |
118
|
|
|
->with($this->identicalTo('_lug_criteria'), $this->identicalTo([$identifier = 'id'])) |
119
|
|
|
->will($this->returnValue([$identifier])); |
120
|
|
|
|
121
|
|
|
$request |
|
|
|
|
122
|
|
|
->expects($this->once()) |
123
|
|
|
->method('get') |
124
|
|
|
->with($this->identicalTo($identifier), $this->isNull()) |
125
|
|
|
->will($this->returnValue($value = 'value')); |
126
|
|
|
|
127
|
|
|
$this->assertSame([$identifier => $value], $this->parameterResolver->resolveCriteria()); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
View Code Duplication |
public function testResolveCriteriaWithExplicit() |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
$this->requestStack |
|
|
|
|
133
|
|
|
->expects($this->exactly(2)) |
134
|
|
|
->method('getMasterRequest') |
135
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
136
|
|
|
|
137
|
|
|
$request->attributes |
138
|
|
|
->expects($this->once()) |
139
|
|
|
->method('get') |
140
|
|
|
->with($this->identicalTo('_lug_criteria'), $this->identicalTo(['id'])) |
141
|
|
|
->will($this->returnValue([$identifier = 'code'])); |
142
|
|
|
|
143
|
|
|
$request |
|
|
|
|
144
|
|
|
->expects($this->once()) |
145
|
|
|
->method('get') |
146
|
|
|
->with($this->identicalTo($identifier), $this->isNull()) |
147
|
|
|
->will($this->returnValue($value = 'value')); |
148
|
|
|
|
149
|
|
|
$this->assertSame([$identifier => $value], $this->parameterResolver->resolveCriteria()); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException |
154
|
|
|
* @expectedExceptionMessage The request could not be found. |
155
|
|
|
*/ |
156
|
|
|
public function testResolveCriteriaMandatoryWithoutRequest() |
157
|
|
|
{ |
158
|
|
|
$this->parameterResolver->resolveCriteria(true); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException |
163
|
|
|
* @expectedExceptionMessage The criteria could not be found for the route "route". |
164
|
|
|
*/ |
165
|
|
View Code Duplication |
public function testResolveCriteriaMandatoryWithoutCriteria() |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
$this->requestStack |
|
|
|
|
168
|
|
|
->expects($this->exactly(2)) |
169
|
|
|
->method('getMasterRequest') |
170
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
171
|
|
|
|
172
|
|
|
$request->attributes |
173
|
|
|
->expects($this->at(0)) |
174
|
|
|
->method('get') |
175
|
|
|
->with($this->identicalTo('_lug_criteria'), $this->identicalTo(['id'])) |
176
|
|
|
->will($this->returnValue([])); |
177
|
|
|
|
178
|
|
|
$request->attributes |
179
|
|
|
->expects($this->at(1)) |
180
|
|
|
->method('get') |
181
|
|
|
->with($this->identicalTo('_route'), $this->isNull()) |
182
|
|
|
->will($this->returnValue('route')); |
183
|
|
|
|
184
|
|
|
$this->parameterResolver->resolveCriteria(true); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException |
189
|
|
|
* @expectedExceptionMessage The criteria "id" could not be found for the route "route". |
190
|
|
|
*/ |
191
|
|
|
public function testResolveCriteriaMandatoryWithoutRequestCriteria() |
192
|
|
|
{ |
193
|
|
|
$this->requestStack |
|
|
|
|
194
|
|
|
->expects($this->exactly(2)) |
195
|
|
|
->method('getMasterRequest') |
196
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
197
|
|
|
|
198
|
|
|
$request->attributes |
199
|
|
|
->expects($this->at(0)) |
200
|
|
|
->method('get') |
201
|
|
|
->with($this->identicalTo('_lug_criteria'), $this->identicalTo([$identifier = 'id'])) |
202
|
|
|
->will($this->returnValue([$identifier])); |
203
|
|
|
|
204
|
|
|
$request->attributes |
205
|
|
|
->expects($this->at(1)) |
206
|
|
|
->method('get') |
207
|
|
|
->with($this->identicalTo('_route'), $this->isNull()) |
208
|
|
|
->will($this->returnValue('route')); |
209
|
|
|
|
210
|
|
|
$request |
|
|
|
|
211
|
|
|
->expects($this->once()) |
212
|
|
|
->method('get') |
213
|
|
|
->with($this->identicalTo($identifier), $this->isNull()) |
214
|
|
|
->will($this->returnValue(null)); |
215
|
|
|
|
216
|
|
|
$this->parameterResolver->resolveCriteria(true); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function testResolveCurrentPageWithoutRequest() |
220
|
|
|
{ |
221
|
|
|
$this->assertSame(1, $this->parameterResolver->resolveCurrentPage()); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function testResolveCurrentPageDefault() |
225
|
|
|
{ |
226
|
|
|
$this->requestStack |
|
|
|
|
227
|
|
|
->expects($this->exactly(2)) |
228
|
|
|
->method('getMasterRequest') |
229
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
230
|
|
|
|
231
|
|
|
$request->attributes |
232
|
|
|
->expects($this->once()) |
233
|
|
|
->method('get') |
234
|
|
|
->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo($pageParameter = 'page')) |
235
|
|
|
->will($this->returnValue($pageParameter)); |
236
|
|
|
|
237
|
|
|
$request |
|
|
|
|
238
|
|
|
->expects($this->once()) |
239
|
|
|
->method('get') |
240
|
|
|
->with($this->identicalTo($pageParameter), $this->identicalTo($page = 1)) |
241
|
|
|
->will($this->returnValue($page)); |
242
|
|
|
|
243
|
|
|
$this->assertSame($page, $this->parameterResolver->resolveCurrentPage()); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
View Code Duplication |
public function testResolveCurrentPageExplicitParameter() |
|
|
|
|
247
|
|
|
{ |
248
|
|
|
$this->requestStack |
|
|
|
|
249
|
|
|
->expects($this->exactly(2)) |
250
|
|
|
->method('getMasterRequest') |
251
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
252
|
|
|
|
253
|
|
|
$request->attributes |
254
|
|
|
->expects($this->once()) |
255
|
|
|
->method('get') |
256
|
|
|
->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo('page')) |
257
|
|
|
->will($this->returnValue($pageParameter = 'p')); |
258
|
|
|
|
259
|
|
|
$request |
|
|
|
|
260
|
|
|
->expects($this->once()) |
261
|
|
|
->method('get') |
262
|
|
|
->with($this->identicalTo($pageParameter), $this->identicalTo($page = 1)) |
263
|
|
|
->will($this->returnValue($page)); |
264
|
|
|
|
265
|
|
|
$this->assertSame($page, $this->parameterResolver->resolveCurrentPage()); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
View Code Duplication |
public function testResolveCurrentPageExplicitPage() |
|
|
|
|
269
|
|
|
{ |
270
|
|
|
$this->requestStack |
|
|
|
|
271
|
|
|
->expects($this->exactly(2)) |
272
|
|
|
->method('getMasterRequest') |
273
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
274
|
|
|
|
275
|
|
|
$request->attributes |
276
|
|
|
->expects($this->once()) |
277
|
|
|
->method('get') |
278
|
|
|
->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo($pageParameter = 'page')) |
279
|
|
|
->will($this->returnValue($pageParameter)); |
280
|
|
|
|
281
|
|
|
$request |
|
|
|
|
282
|
|
|
->expects($this->once()) |
283
|
|
|
->method('get') |
284
|
|
|
->with($this->identicalTo($pageParameter), $this->identicalTo(1)) |
285
|
|
|
->will($this->returnValue($page = 2)); |
286
|
|
|
|
287
|
|
|
$this->assertSame($page, $this->parameterResolver->resolveCurrentPage()); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
public function testResolveFormWithoutRequest() |
291
|
|
|
{ |
292
|
|
|
$resource = $this->createResourceMock(); |
293
|
|
|
$resource |
|
|
|
|
294
|
|
|
->expects($this->once()) |
295
|
|
|
->method('getForm') |
296
|
|
|
->will($this->returnValue($form = 'form')); |
297
|
|
|
|
298
|
|
|
$this->assertSame($form, $this->parameterResolver->resolveForm($resource)); |
|
|
|
|
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
public function testResolveFormDefault() |
302
|
|
|
{ |
303
|
|
|
$resource = $this->createResourceMock(); |
304
|
|
|
$resource |
|
|
|
|
305
|
|
|
->expects($this->once()) |
306
|
|
|
->method('getForm') |
307
|
|
|
->will($this->returnValue($form = 'form')); |
308
|
|
|
|
309
|
|
|
$this->requestStack |
|
|
|
|
310
|
|
|
->expects($this->once()) |
311
|
|
|
->method('getMasterRequest') |
312
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
313
|
|
|
|
314
|
|
|
$request->attributes |
315
|
|
|
->expects($this->once()) |
316
|
|
|
->method('get') |
317
|
|
|
->with($this->identicalTo('_lug_form'), $this->identicalTo($form)) |
318
|
|
|
->will($this->returnValue($form)); |
319
|
|
|
|
320
|
|
|
$this->assertSame($form, $this->parameterResolver->resolveForm($resource)); |
|
|
|
|
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
public function testResolveFormExplicit() |
324
|
|
|
{ |
325
|
|
|
$resource = $this->createResourceMock(); |
326
|
|
|
$resource |
|
|
|
|
327
|
|
|
->expects($this->once()) |
328
|
|
|
->method('getForm') |
329
|
|
|
->will($this->returnValue($form = 'form')); |
330
|
|
|
|
331
|
|
|
$this->requestStack |
|
|
|
|
332
|
|
|
->expects($this->once()) |
333
|
|
|
->method('getMasterRequest') |
334
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
335
|
|
|
|
336
|
|
|
$request->attributes |
337
|
|
|
->expects($this->once()) |
338
|
|
|
->method('get') |
339
|
|
|
->with($this->identicalTo('_lug_form'), $this->identicalTo($form)) |
340
|
|
|
->will($this->returnValue($explicitForm = 'explicit_form')); |
341
|
|
|
|
342
|
|
|
$this->assertSame($explicitForm, $this->parameterResolver->resolveForm($resource)); |
|
|
|
|
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
public function testResolveGrid() |
346
|
|
|
{ |
347
|
|
|
$this->requestStack |
|
|
|
|
348
|
|
|
->expects($this->exactly(2)) |
349
|
|
|
->method('getMasterRequest') |
350
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
351
|
|
|
|
352
|
|
|
$request->attributes |
353
|
|
|
->expects($this->once()) |
354
|
|
|
->method('get') |
355
|
|
|
->with($this->identicalTo('_lug_grid'), $this->identicalTo([])) |
356
|
|
|
->will($this->returnValue($grid = ['foo' => 'bar'])); |
357
|
|
|
|
358
|
|
|
$this->assertSame( |
359
|
|
|
array_merge(['resource' => $resource = $this->createResourceMock()], $grid), |
360
|
|
|
$this->parameterResolver->resolveGrid($resource) |
|
|
|
|
361
|
|
|
); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException |
366
|
|
|
* @expectedExceptionMessage The request could not be found. |
367
|
|
|
*/ |
368
|
|
|
public function testResolveGridWithoutRequest() |
369
|
|
|
{ |
370
|
|
|
$this->parameterResolver->resolveGrid($this->createResourceMock()); |
|
|
|
|
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
public function testResolveHateoasWithoutRequest() |
374
|
|
|
{ |
375
|
|
|
$this->assertFalse($this->parameterResolver->resolveHateoas()); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
public function testResolveHateoasDefault() |
379
|
|
|
{ |
380
|
|
|
$this->requestStack |
|
|
|
|
381
|
|
|
->expects($this->once()) |
382
|
|
|
->method('getMasterRequest') |
383
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
384
|
|
|
|
385
|
|
|
$request->attributes |
386
|
|
|
->expects($this->once()) |
387
|
|
|
->method('get') |
388
|
|
|
->with($this->identicalTo('_lug_hateoas'), $this->identicalTo($hateaos = false)) |
389
|
|
|
->will($this->returnValue($hateaos)); |
390
|
|
|
|
391
|
|
|
$this->assertFalse($this->parameterResolver->resolveHateoas()); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
public function testResolveHateoasExplicit() |
395
|
|
|
{ |
396
|
|
|
$this->requestStack |
|
|
|
|
397
|
|
|
->expects($this->once()) |
398
|
|
|
->method('getMasterRequest') |
399
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
400
|
|
|
|
401
|
|
|
$request->attributes |
402
|
|
|
->expects($this->once()) |
403
|
|
|
->method('get') |
404
|
|
|
->with($this->identicalTo('_lug_hateoas'), $this->identicalTo(false)) |
405
|
|
|
->will($this->returnValue(true)); |
406
|
|
|
|
407
|
|
|
$this->assertTrue($this->parameterResolver->resolveHateoas()); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
public function testResolveLocationRoute() |
411
|
|
|
{ |
412
|
|
|
$this->requestStack |
|
|
|
|
413
|
|
|
->expects($this->exactly(2)) |
414
|
|
|
->method('getMasterRequest') |
415
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
416
|
|
|
|
417
|
|
|
$request->attributes |
418
|
|
|
->expects($this->once()) |
419
|
|
|
->method('get') |
420
|
|
|
->with($this->identicalTo('_lug_location_route'), $this->isNull()) |
421
|
|
|
->will($this->returnValue($route = 'route')); |
422
|
|
|
|
423
|
|
|
$this->assertSame($route, $this->parameterResolver->resolveLocationRoute()); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException |
428
|
|
|
* @expectedExceptionMessage The request could not be found. |
429
|
|
|
*/ |
430
|
|
|
public function testResolveLocationRouteWithoutRequest() |
431
|
|
|
{ |
432
|
|
|
$this->parameterResolver->resolveLocationRoute(); |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException |
437
|
|
|
* @expectedExceptionMessage The location route could not be found for the route "route". |
438
|
|
|
*/ |
439
|
|
View Code Duplication |
public function testResolveLocationRouteMissing() |
|
|
|
|
440
|
|
|
{ |
441
|
|
|
$this->requestStack |
|
|
|
|
442
|
|
|
->expects($this->exactly(2)) |
443
|
|
|
->method('getMasterRequest') |
444
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
445
|
|
|
|
446
|
|
|
$request->attributes |
447
|
|
|
->expects($this->at(0)) |
448
|
|
|
->method('get') |
449
|
|
|
->with($this->identicalTo('_lug_location_route'), $this->isNull()) |
450
|
|
|
->will($this->returnValue(null)); |
451
|
|
|
|
452
|
|
|
$request->attributes |
453
|
|
|
->expects($this->at(1)) |
454
|
|
|
->method('get') |
455
|
|
|
->with($this->identicalTo('_route'), $this->isNull()) |
456
|
|
|
->will($this->returnValue('route')); |
457
|
|
|
|
458
|
|
|
$this->parameterResolver->resolveLocationRoute(); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
public function testResolveLocationRouteParametersWithoutRequest() |
462
|
|
|
{ |
463
|
|
|
$this->assertEmpty($this->parameterResolver->resolveLocationRouteParameters(new \stdClass())); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
public function testResolveLocationRouteParametersDefault() |
467
|
|
|
{ |
468
|
|
|
$this->requestStack |
|
|
|
|
469
|
|
|
->expects($this->once()) |
470
|
|
|
->method('getMasterRequest') |
471
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
472
|
|
|
|
473
|
|
|
$request->attributes |
474
|
|
|
->expects($this->once()) |
475
|
|
|
->method('get') |
476
|
|
|
->with($this->identicalTo('_lug_location_route_parameters'), $this->identicalTo($parameters = [])) |
477
|
|
|
->will($this->returnValue($parameters)); |
478
|
|
|
|
479
|
|
|
$this->assertEmpty($this->parameterResolver->resolveLocationRouteParameters(new \stdClass())); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
View Code Duplication |
public function testResolveLocationRouteParametersExplicit() |
|
|
|
|
483
|
|
|
{ |
484
|
|
|
$this->requestStack |
|
|
|
|
485
|
|
|
->expects($this->once()) |
486
|
|
|
->method('getMasterRequest') |
487
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
488
|
|
|
|
489
|
|
|
$request->attributes |
490
|
|
|
->expects($this->once()) |
491
|
|
|
->method('get') |
492
|
|
|
->with($this->identicalTo('_lug_location_route_parameters'), $this->identicalTo([])) |
493
|
|
|
->will($this->returnValue([$parameter = 'id'])); |
494
|
|
|
|
495
|
|
|
$object = new \stdClass(); |
496
|
|
|
$object->{$parameter} = $value = 1; |
497
|
|
|
|
498
|
|
|
$this->propertyAccessor |
|
|
|
|
499
|
|
|
->expects($this->once()) |
500
|
|
|
->method('getValue') |
501
|
|
|
->with($this->identicalTo($object), $this->identicalTo($parameter)) |
502
|
|
|
->will($this->returnValue($value)); |
503
|
|
|
|
504
|
|
|
$this->assertSame([$parameter => $value], $this->parameterResolver->resolveLocationRouteParameters($object)); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
public function testResolveMaxPerPageWithoutRequest() |
508
|
|
|
{ |
509
|
|
|
$this->assertSame(10, $this->parameterResolver->resolveMaxPerPage()); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
public function testResolveMaxPerPageDefault() |
513
|
|
|
{ |
514
|
|
|
$this->requestStack |
|
|
|
|
515
|
|
|
->expects($this->once()) |
516
|
|
|
->method('getMasterRequest') |
517
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
518
|
|
|
|
519
|
|
|
$request->attributes |
520
|
|
|
->expects($this->once()) |
521
|
|
|
->method('get') |
522
|
|
|
->with($this->identicalTo('_lug_max_per_page'), $this->identicalTo($maxPerPage = 10)) |
523
|
|
|
->will($this->returnValue($maxPerPage)); |
524
|
|
|
|
525
|
|
|
$this->assertSame($maxPerPage, $this->parameterResolver->resolveMaxPerPage()); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
public function testResolveMaxPerPageExplicit() |
529
|
|
|
{ |
530
|
|
|
$this->requestStack |
|
|
|
|
531
|
|
|
->expects($this->once()) |
532
|
|
|
->method('getMasterRequest') |
533
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
534
|
|
|
|
535
|
|
|
$request->attributes |
536
|
|
|
->expects($this->once()) |
537
|
|
|
->method('get') |
538
|
|
|
->with($this->identicalTo('_lug_max_per_page'), $this->identicalTo(10)) |
539
|
|
|
->will($this->returnValue($maxPerPage = 5)); |
540
|
|
|
|
541
|
|
|
$this->assertSame($maxPerPage, $this->parameterResolver->resolveMaxPerPage()); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
public function testResolveRedirectRoute() |
545
|
|
|
{ |
546
|
|
|
$this->requestStack |
|
|
|
|
547
|
|
|
->expects($this->exactly(2)) |
548
|
|
|
->method('getMasterRequest') |
549
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
550
|
|
|
|
551
|
|
|
$request->attributes |
552
|
|
|
->expects($this->once()) |
553
|
|
|
->method('get') |
554
|
|
|
->with($this->identicalTo('_lug_redirect_route'), $this->isNull()) |
555
|
|
|
->will($this->returnValue($route = 'route')); |
556
|
|
|
|
557
|
|
|
$this->assertSame($route, $this->parameterResolver->resolveRedirectRoute()); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException |
562
|
|
|
* @expectedExceptionMessage The request could not be found. |
563
|
|
|
*/ |
564
|
|
|
public function testResolveRedirectRouteWithoutRequest() |
565
|
|
|
{ |
566
|
|
|
$this->parameterResolver->resolveRedirectRoute(); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException |
571
|
|
|
* @expectedExceptionMessage The redirect route could not be found for the route "route". |
572
|
|
|
*/ |
573
|
|
View Code Duplication |
public function testResolveRedirectRouteMissing() |
|
|
|
|
574
|
|
|
{ |
575
|
|
|
$this->requestStack |
|
|
|
|
576
|
|
|
->expects($this->exactly(2)) |
577
|
|
|
->method('getMasterRequest') |
578
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
579
|
|
|
|
580
|
|
|
$request->attributes |
581
|
|
|
->expects($this->at(0)) |
582
|
|
|
->method('get') |
583
|
|
|
->with($this->identicalTo('_lug_redirect_route'), $this->isNull()) |
584
|
|
|
->will($this->returnValue(null)); |
585
|
|
|
|
586
|
|
|
$request->attributes |
587
|
|
|
->expects($this->at(1)) |
588
|
|
|
->method('get') |
589
|
|
|
->with($this->identicalTo('_route'), $this->isNull()) |
590
|
|
|
->will($this->returnValue('route')); |
591
|
|
|
|
592
|
|
|
$this->parameterResolver->resolveRedirectRoute(); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
public function testResolveRedirectRouteParametersWithoutRequest() |
596
|
|
|
{ |
597
|
|
|
$this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters(new \stdClass())); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
public function testResolveRedirectRouteParametersDefault() |
601
|
|
|
{ |
602
|
|
|
$this->requestStack |
|
|
|
|
603
|
|
|
->expects($this->once()) |
604
|
|
|
->method('getMasterRequest') |
605
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
606
|
|
|
|
607
|
|
|
$request->attributes |
608
|
|
|
->expects($this->once()) |
609
|
|
|
->method('get') |
610
|
|
|
->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo($parameters = [])) |
611
|
|
|
->will($this->returnValue($parameters)); |
612
|
|
|
|
613
|
|
|
$this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters(new \stdClass())); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
View Code Duplication |
public function testResolveRedirectRouteParametersExplicit() |
|
|
|
|
617
|
|
|
{ |
618
|
|
|
$this->requestStack |
|
|
|
|
619
|
|
|
->expects($this->once()) |
620
|
|
|
->method('getMasterRequest') |
621
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
622
|
|
|
|
623
|
|
|
$request->attributes |
624
|
|
|
->expects($this->once()) |
625
|
|
|
->method('get') |
626
|
|
|
->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([])) |
627
|
|
|
->will($this->returnValue([$parameter = 'id'])); |
628
|
|
|
|
629
|
|
|
$object = new \stdClass(); |
630
|
|
|
$object->{$parameter} = $value = 1; |
631
|
|
|
|
632
|
|
|
$this->propertyAccessor |
|
|
|
|
633
|
|
|
->expects($this->once()) |
634
|
|
|
->method('getValue') |
635
|
|
|
->with($this->identicalTo($object), $this->identicalTo($parameter)) |
636
|
|
|
->will($this->returnValue($value)); |
637
|
|
|
|
638
|
|
|
$this->assertSame([$parameter => $value], $this->parameterResolver->resolveRedirectRouteParameters($object)); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
public function testResolveRedirectRouteParametersForwardParameters() |
642
|
|
|
{ |
643
|
|
|
$this->requestStack |
|
|
|
|
644
|
|
|
->expects($this->exactly(2)) |
645
|
|
|
->method('getMasterRequest') |
646
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
647
|
|
|
|
648
|
|
|
$request->attributes |
649
|
|
|
->expects($this->once()) |
650
|
|
|
->method('get') |
651
|
|
|
->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([])) |
652
|
|
|
->will($this->returnValue([$parameter = 'id'])); |
653
|
|
|
|
654
|
|
|
$request->query = $this->createParameterBagMock(); |
655
|
|
|
$request->query |
|
|
|
|
656
|
|
|
->expects($this->once()) |
657
|
|
|
->method('all') |
658
|
|
|
->will($this->returnValue($query = ['foo' => 'bar'])); |
659
|
|
|
|
660
|
|
|
$object = new \stdClass(); |
661
|
|
|
$object->{$parameter} = $value = 1; |
662
|
|
|
|
663
|
|
|
$this->propertyAccessor |
|
|
|
|
664
|
|
|
->expects($this->once()) |
665
|
|
|
->method('getValue') |
666
|
|
|
->with($this->identicalTo($object), $this->identicalTo($parameter)) |
667
|
|
|
->will($this->returnValue($value)); |
668
|
|
|
|
669
|
|
|
$this->assertSame( |
670
|
|
|
array_merge($query, [$parameter => $value]), |
671
|
|
|
$this->parameterResolver->resolveRedirectRouteParameters($object, true) |
672
|
|
|
); |
673
|
|
|
} |
674
|
|
|
|
675
|
|
View Code Duplication |
public function testResolveRedirectRouteParametersWithoutObject() |
|
|
|
|
676
|
|
|
{ |
677
|
|
|
$this->requestStack |
|
|
|
|
678
|
|
|
->expects($this->once()) |
679
|
|
|
->method('getMasterRequest') |
680
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
681
|
|
|
|
682
|
|
|
$request->attributes |
683
|
|
|
->expects($this->once()) |
684
|
|
|
->method('get') |
685
|
|
|
->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([])) |
686
|
|
|
->will($this->returnValue([])); |
687
|
|
|
|
688
|
|
|
$this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters()); |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException |
693
|
|
|
* @expectedExceptionMessage The route parameters could not be found for the route "redirect_route_parameters". |
694
|
|
|
*/ |
695
|
|
View Code Duplication |
public function testResolveRedirectRouteParametersWithObjectMissing() |
|
|
|
|
696
|
|
|
{ |
697
|
|
|
$this->requestStack |
|
|
|
|
698
|
|
|
->expects($this->once()) |
699
|
|
|
->method('getMasterRequest') |
700
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
701
|
|
|
|
702
|
|
|
$request->attributes |
703
|
|
|
->expects($this->once()) |
704
|
|
|
->method('get') |
705
|
|
|
->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([])) |
706
|
|
|
->will($this->returnValue(['id'])); |
707
|
|
|
|
708
|
|
|
$this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters()); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
public function testResolveRedirectRouteParametersForwardWithoutRequest() |
712
|
|
|
{ |
713
|
|
|
$this->assertFalse($this->parameterResolver->resolveRedirectRouteParametersForward()); |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
public function testResolveRedirectRouteParametersForwardDefault() |
717
|
|
|
{ |
718
|
|
|
$this->requestStack |
|
|
|
|
719
|
|
|
->expects($this->once()) |
720
|
|
|
->method('getMasterRequest') |
721
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
722
|
|
|
|
723
|
|
|
$request->attributes |
724
|
|
|
->expects($this->once()) |
725
|
|
|
->method('get') |
726
|
|
|
->with($this->identicalTo('_lug_redirect_route_parameters_forward'), $this->identicalTo($forward = false)) |
727
|
|
|
->will($this->returnValue($forward)); |
728
|
|
|
|
729
|
|
|
$this->assertFalse($this->parameterResolver->resolveRedirectRouteParametersForward()); |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
public function testResolveRedirectRouteParametersForwardExplicit() |
733
|
|
|
{ |
734
|
|
|
$this->requestStack |
|
|
|
|
735
|
|
|
->expects($this->once()) |
736
|
|
|
->method('getMasterRequest') |
737
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
738
|
|
|
|
739
|
|
|
$request->attributes |
740
|
|
|
->expects($this->once()) |
741
|
|
|
->method('get') |
742
|
|
|
->with($this->identicalTo('_lug_redirect_route_parameters_forward'), $this->identicalTo(false)) |
743
|
|
|
->will($this->returnValue(true)); |
744
|
|
|
|
745
|
|
|
$this->assertTrue($this->parameterResolver->resolveRedirectRouteParametersForward()); |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
public function testResolveRepositoryMethodWithoutRequest() |
749
|
|
|
{ |
750
|
|
|
$this->assertSame('findForTest', $this->parameterResolver->resolveRepositoryMethod('test')); |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
public function testResolveRepositoryMethodDefault() |
754
|
|
|
{ |
755
|
|
|
$this->requestStack |
|
|
|
|
756
|
|
|
->expects($this->once()) |
757
|
|
|
->method('getMasterRequest') |
758
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
759
|
|
|
|
760
|
|
|
$request->attributes |
761
|
|
|
->expects($this->once()) |
762
|
|
|
->method('get') |
763
|
|
|
->with($this->identicalTo('_lug_repository_method'), $this->identicalTo($repositoryMethod = 'findForTest')) |
764
|
|
|
->will($this->returnValue($repositoryMethod)); |
765
|
|
|
|
766
|
|
|
$this->assertSame($repositoryMethod, $this->parameterResolver->resolveRepositoryMethod('test')); |
767
|
|
|
} |
768
|
|
|
|
769
|
|
|
public function testResolveRepositoryMethodExplicit() |
770
|
|
|
{ |
771
|
|
|
$this->requestStack |
|
|
|
|
772
|
|
|
->expects($this->once()) |
773
|
|
|
->method('getMasterRequest') |
774
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
775
|
|
|
|
776
|
|
|
$request->attributes |
777
|
|
|
->expects($this->once()) |
778
|
|
|
->method('get') |
779
|
|
|
->with($this->identicalTo('_lug_repository_method'), $this->identicalTo('findForTest')) |
780
|
|
|
->will($this->returnValue($repositoryMethod = 'findForAction')); |
781
|
|
|
|
782
|
|
|
$this->assertSame($repositoryMethod, $this->parameterResolver->resolveRepositoryMethod('test')); |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
public function testResolveSerializerGroupsWithoutRequest() |
786
|
|
|
{ |
787
|
|
|
$this->assertEmpty($this->parameterResolver->resolveSerializerGroups()); |
788
|
|
|
} |
789
|
|
|
|
790
|
|
View Code Duplication |
public function testResolveSerializerGroupsDefault() |
|
|
|
|
791
|
|
|
{ |
792
|
|
|
$this->requestStack |
|
|
|
|
793
|
|
|
->expects($this->once()) |
794
|
|
|
->method('getMasterRequest') |
795
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
796
|
|
|
|
797
|
|
|
$request->attributes |
798
|
|
|
->expects($this->once()) |
799
|
|
|
->method('get') |
800
|
|
|
->with($this->identicalTo('_lug_serializer_groups'), $this->identicalTo($groups = [])) |
801
|
|
|
->will($this->returnValue($groups)); |
802
|
|
|
|
803
|
|
|
$this->assertEmpty($this->parameterResolver->resolveSerializerGroups()); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
View Code Duplication |
public function testResolveSerializerGroupsExplicit() |
|
|
|
|
807
|
|
|
{ |
808
|
|
|
$this->requestStack |
|
|
|
|
809
|
|
|
->expects($this->once()) |
810
|
|
|
->method('getMasterRequest') |
811
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
812
|
|
|
|
813
|
|
|
$request->attributes |
814
|
|
|
->expects($this->once()) |
815
|
|
|
->method('get') |
816
|
|
|
->with($this->identicalTo('_lug_serializer_groups'), $this->identicalTo([])) |
817
|
|
|
->will($this->returnValue($groups = ['group'])); |
818
|
|
|
|
819
|
|
|
$this->assertSame($groups, $this->parameterResolver->resolveSerializerGroups()); |
820
|
|
|
} |
821
|
|
|
|
822
|
|
|
public function testResolveSerializerNullWithoutRequest() |
823
|
|
|
{ |
824
|
|
|
$this->assertTrue($this->parameterResolver->resolveSerializerNull()); |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
public function testResolveSerializerNullDefault() |
828
|
|
|
{ |
829
|
|
|
$this->requestStack |
|
|
|
|
830
|
|
|
->expects($this->once()) |
831
|
|
|
->method('getMasterRequest') |
832
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
833
|
|
|
|
834
|
|
|
$request->attributes |
835
|
|
|
->expects($this->once()) |
836
|
|
|
->method('get') |
837
|
|
|
->with($this->identicalTo('_lug_serializer_null'), $this->identicalTo($null = true)) |
838
|
|
|
->will($this->returnValue($null)); |
839
|
|
|
|
840
|
|
|
$this->assertTrue($this->parameterResolver->resolveSerializerNull()); |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
public function testResolveSerializerNullExplicit() |
844
|
|
|
{ |
845
|
|
|
$this->requestStack |
|
|
|
|
846
|
|
|
->expects($this->once()) |
847
|
|
|
->method('getMasterRequest') |
848
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
849
|
|
|
|
850
|
|
|
$request->attributes |
851
|
|
|
->expects($this->once()) |
852
|
|
|
->method('get') |
853
|
|
|
->with($this->identicalTo('_lug_serializer_null'), $this->identicalTo(true)) |
854
|
|
|
->will($this->returnValue(false)); |
855
|
|
|
|
856
|
|
|
$this->assertFalse($this->parameterResolver->resolveSerializerNull()); |
857
|
|
|
} |
858
|
|
|
|
859
|
|
|
public function testResolveSortingWithoutRequest() |
860
|
|
|
{ |
861
|
|
|
$this->assertEmpty($this->parameterResolver->resolveSorting()); |
862
|
|
|
} |
863
|
|
|
|
864
|
|
View Code Duplication |
public function testResolveSortingDefault() |
|
|
|
|
865
|
|
|
{ |
866
|
|
|
$this->requestStack |
|
|
|
|
867
|
|
|
->expects($this->once()) |
868
|
|
|
->method('getMasterRequest') |
869
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
870
|
|
|
|
871
|
|
|
$request->attributes |
872
|
|
|
->expects($this->once()) |
873
|
|
|
->method('get') |
874
|
|
|
->with($this->identicalTo('_lug_sorting'), $this->identicalTo($sorting = [])) |
875
|
|
|
->will($this->returnValue($sorting)); |
876
|
|
|
|
877
|
|
|
$this->assertEmpty($this->parameterResolver->resolveSorting()); |
878
|
|
|
} |
879
|
|
|
|
880
|
|
View Code Duplication |
public function testResolveSortingExplicit() |
|
|
|
|
881
|
|
|
{ |
882
|
|
|
$this->requestStack |
|
|
|
|
883
|
|
|
->expects($this->once()) |
884
|
|
|
->method('getMasterRequest') |
885
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
886
|
|
|
|
887
|
|
|
$request->attributes |
888
|
|
|
->expects($this->once()) |
889
|
|
|
->method('get') |
890
|
|
|
->with($this->identicalTo('_lug_sorting'), $this->identicalTo([])) |
891
|
|
|
->will($this->returnValue($sorting = ['foo' => 'ASC'])); |
892
|
|
|
|
893
|
|
|
$this->assertSame($sorting, $this->parameterResolver->resolveSorting()); |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
public function testResolveTemplate() |
897
|
|
|
{ |
898
|
|
|
$this->requestStack |
|
|
|
|
899
|
|
|
->expects($this->exactly(2)) |
900
|
|
|
->method('getMasterRequest') |
901
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
902
|
|
|
|
903
|
|
|
$request->attributes |
904
|
|
|
->expects($this->once()) |
905
|
|
|
->method('get') |
906
|
|
|
->with($this->identicalTo('_lug_template'), $this->isNull()) |
907
|
|
|
->will($this->returnValue($template = 'template')); |
908
|
|
|
|
909
|
|
|
$this->assertSame($template, $this->parameterResolver->resolveTemplate()); |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
/** |
913
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException |
914
|
|
|
* @expectedExceptionMessage The request could not be found. |
915
|
|
|
*/ |
916
|
|
|
public function testResolveTemplateWithoutRequest() |
917
|
|
|
{ |
918
|
|
|
$this->parameterResolver->resolveTemplate(); |
919
|
|
|
} |
920
|
|
|
|
921
|
|
|
/** |
922
|
|
|
* @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException |
923
|
|
|
* @expectedExceptionMessage The template could not be found for the route "route". |
924
|
|
|
*/ |
925
|
|
View Code Duplication |
public function testResolveTemplateMissing() |
|
|
|
|
926
|
|
|
{ |
927
|
|
|
$this->requestStack |
|
|
|
|
928
|
|
|
->expects($this->exactly(2)) |
929
|
|
|
->method('getMasterRequest') |
930
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
931
|
|
|
|
932
|
|
|
$request->attributes |
933
|
|
|
->expects($this->at(0)) |
934
|
|
|
->method('get') |
935
|
|
|
->with($this->identicalTo('_lug_template'), $this->isNull()) |
936
|
|
|
->will($this->returnValue(null)); |
937
|
|
|
|
938
|
|
|
$request->attributes |
939
|
|
|
->expects($this->at(1)) |
940
|
|
|
->method('get') |
941
|
|
|
->with($this->identicalTo('_route'), $this->isNull()) |
942
|
|
|
->will($this->returnValue('route')); |
943
|
|
|
|
944
|
|
|
$this->parameterResolver->resolveTemplate(); |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
public function testResolveThemesWithoutRequest() |
948
|
|
|
{ |
949
|
|
|
$this->assertEmpty($this->parameterResolver->resolveThemes()); |
950
|
|
|
} |
951
|
|
|
|
952
|
|
View Code Duplication |
public function testResolveThemesDefault() |
|
|
|
|
953
|
|
|
{ |
954
|
|
|
$this->requestStack |
|
|
|
|
955
|
|
|
->expects($this->once()) |
956
|
|
|
->method('getMasterRequest') |
957
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
958
|
|
|
|
959
|
|
|
$request->attributes |
960
|
|
|
->expects($this->once()) |
961
|
|
|
->method('get') |
962
|
|
|
->with($this->identicalTo('_lug_themes'), $this->identicalTo($themes = [])) |
963
|
|
|
->will($this->returnValue($themes)); |
964
|
|
|
|
965
|
|
|
$this->assertEmpty($this->parameterResolver->resolveThemes()); |
966
|
|
|
} |
967
|
|
|
|
968
|
|
View Code Duplication |
public function testResolveThemesExplicit() |
|
|
|
|
969
|
|
|
{ |
970
|
|
|
$this->requestStack |
|
|
|
|
971
|
|
|
->expects($this->once()) |
972
|
|
|
->method('getMasterRequest') |
973
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
974
|
|
|
|
975
|
|
|
$request->attributes |
976
|
|
|
->expects($this->once()) |
977
|
|
|
->method('get') |
978
|
|
|
->with($this->identicalTo('_lug_themes'), $this->identicalTo([])) |
979
|
|
|
->will($this->returnValue($themes = ['theme'])); |
980
|
|
|
|
981
|
|
|
$this->assertSame($themes, $this->parameterResolver->resolveThemes()); |
982
|
|
|
} |
983
|
|
|
|
984
|
|
|
public function testResolveTranslationDomainWithoutRequest() |
985
|
|
|
{ |
986
|
|
|
$this->assertSame('forms', $this->parameterResolver->resolveTranslationDomain()); |
987
|
|
|
} |
988
|
|
|
|
989
|
|
View Code Duplication |
public function testResolveTranslationDomainDefault() |
|
|
|
|
990
|
|
|
{ |
991
|
|
|
$this->requestStack |
|
|
|
|
992
|
|
|
->expects($this->exactly(2)) |
993
|
|
|
->method('getMasterRequest') |
994
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
995
|
|
|
|
996
|
|
|
$request->attributes |
997
|
|
|
->expects($this->at(0)) |
998
|
|
|
->method('get') |
999
|
|
|
->with($this->identicalTo('_lug_grid'), $this->isNull()) |
1000
|
|
|
->will($this->returnValue(null)); |
1001
|
|
|
|
1002
|
|
|
$request->attributes |
1003
|
|
|
->expects($this->at(1)) |
1004
|
|
|
->method('get') |
1005
|
|
|
->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo($translationDomain = 'forms')) |
1006
|
|
|
->will($this->returnValue($translationDomain)); |
1007
|
|
|
|
1008
|
|
|
$this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain()); |
1009
|
|
|
} |
1010
|
|
|
|
1011
|
|
View Code Duplication |
public function testResolveTranslationDomainExplicit() |
|
|
|
|
1012
|
|
|
{ |
1013
|
|
|
$this->requestStack |
|
|
|
|
1014
|
|
|
->expects($this->exactly(2)) |
1015
|
|
|
->method('getMasterRequest') |
1016
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
1017
|
|
|
|
1018
|
|
|
$request->attributes |
1019
|
|
|
->expects($this->at(0)) |
1020
|
|
|
->method('get') |
1021
|
|
|
->with($this->identicalTo('_lug_grid'), $this->isNull()) |
1022
|
|
|
->will($this->returnValue(null)); |
1023
|
|
|
|
1024
|
|
|
$request->attributes |
1025
|
|
|
->expects($this->at(1)) |
1026
|
|
|
->method('get') |
1027
|
|
|
->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo('forms')) |
1028
|
|
|
->will($this->returnValue($translationDomain = 'translation_domain')); |
1029
|
|
|
|
1030
|
|
|
$this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain()); |
1031
|
|
|
} |
1032
|
|
|
|
1033
|
|
View Code Duplication |
public function testResolveTranslationDomainWithGrid() |
|
|
|
|
1034
|
|
|
{ |
1035
|
|
|
$this->requestStack |
|
|
|
|
1036
|
|
|
->expects($this->exactly(2)) |
1037
|
|
|
->method('getMasterRequest') |
1038
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
1039
|
|
|
|
1040
|
|
|
$request->attributes |
1041
|
|
|
->expects($this->at(0)) |
1042
|
|
|
->method('get') |
1043
|
|
|
->with($this->identicalTo('_lug_grid'), $this->isNull()) |
1044
|
|
|
->will($this->returnValue(['grid'])); |
1045
|
|
|
|
1046
|
|
|
$request->attributes |
1047
|
|
|
->expects($this->at(1)) |
1048
|
|
|
->method('get') |
1049
|
|
|
->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo($translationDomain = 'grids')) |
1050
|
|
|
->will($this->returnValue($translationDomain)); |
1051
|
|
|
|
1052
|
|
|
$this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain()); |
1053
|
|
|
} |
1054
|
|
|
|
1055
|
|
View Code Duplication |
public function testResolveTranslationDomainExplicitWithGrid() |
|
|
|
|
1056
|
|
|
{ |
1057
|
|
|
$this->requestStack |
|
|
|
|
1058
|
|
|
->expects($this->exactly(2)) |
1059
|
|
|
->method('getMasterRequest') |
1060
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
1061
|
|
|
|
1062
|
|
|
$request->attributes |
1063
|
|
|
->expects($this->at(0)) |
1064
|
|
|
->method('get') |
1065
|
|
|
->with($this->identicalTo('_lug_grid'), $this->isNull()) |
1066
|
|
|
->will($this->returnValue(['grid'])); |
1067
|
|
|
|
1068
|
|
|
$request->attributes |
1069
|
|
|
->expects($this->at(1)) |
1070
|
|
|
->method('get') |
1071
|
|
|
->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo('grids')) |
1072
|
|
|
->will($this->returnValue($translationDomain = 'translation_domain')); |
1073
|
|
|
|
1074
|
|
|
$this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain()); |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
public function testResolveValidationGroupsWithoutRequest() |
1078
|
|
|
{ |
1079
|
|
|
$this->assertEmpty($this->parameterResolver->resolveValidationGroups()); |
1080
|
|
|
} |
1081
|
|
|
|
1082
|
|
View Code Duplication |
public function testResolveValidationGroupsDefault() |
|
|
|
|
1083
|
|
|
{ |
1084
|
|
|
$this->requestStack |
|
|
|
|
1085
|
|
|
->expects($this->once()) |
1086
|
|
|
->method('getMasterRequest') |
1087
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
1088
|
|
|
|
1089
|
|
|
$request->attributes |
1090
|
|
|
->expects($this->once()) |
1091
|
|
|
->method('get') |
1092
|
|
|
->with($this->identicalTo('_lug_validation_groups'), $this->identicalTo($groups = [])) |
1093
|
|
|
->will($this->returnValue($groups)); |
1094
|
|
|
|
1095
|
|
|
$this->assertEmpty($this->parameterResolver->resolveValidationGroups()); |
1096
|
|
|
} |
1097
|
|
|
|
1098
|
|
View Code Duplication |
public function testResolveValidationGroupsExplicit() |
|
|
|
|
1099
|
|
|
{ |
1100
|
|
|
$this->requestStack |
|
|
|
|
1101
|
|
|
->expects($this->once()) |
1102
|
|
|
->method('getMasterRequest') |
1103
|
|
|
->will($this->returnValue($request = $this->createRequestMock())); |
1104
|
|
|
|
1105
|
|
|
$request->attributes |
1106
|
|
|
->expects($this->once()) |
1107
|
|
|
->method('get') |
1108
|
|
|
->with($this->identicalTo('_lug_validation_groups'), $this->identicalTo([])) |
1109
|
|
|
->will($this->returnValue($groups = ['group'])); |
1110
|
|
|
|
1111
|
|
|
$this->assertSame($groups, $this->parameterResolver->resolveValidationGroups()); |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
|
|
/** |
1115
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|RequestStack |
1116
|
|
|
*/ |
1117
|
|
|
private function createRequestStackMock() |
1118
|
|
|
{ |
1119
|
|
|
return $this->getMock(RequestStack::class); |
|
|
|
|
1120
|
|
|
} |
1121
|
|
|
|
1122
|
|
|
/** |
1123
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface |
1124
|
|
|
*/ |
1125
|
|
|
private function createPropertyAccessorMock() |
1126
|
|
|
{ |
1127
|
|
|
return $this->getMock(PropertyAccessorInterface::class); |
|
|
|
|
1128
|
|
|
} |
1129
|
|
|
|
1130
|
|
|
/** |
1131
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|Request |
1132
|
|
|
*/ |
1133
|
|
|
private function createRequestMock() |
1134
|
|
|
{ |
1135
|
|
|
$request = $this->getMock(Request::class); |
|
|
|
|
1136
|
|
|
$request->attributes = $this->createParameterBagMock(); |
1137
|
|
|
|
1138
|
|
|
return $request; |
1139
|
|
|
} |
1140
|
|
|
|
1141
|
|
|
/** |
1142
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ParameterBag |
1143
|
|
|
*/ |
1144
|
|
|
private function createParameterBagMock() |
1145
|
|
|
{ |
1146
|
|
|
return $this->getMock(ParameterBag::class); |
|
|
|
|
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
/** |
1150
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface |
1151
|
|
|
*/ |
1152
|
|
|
private function createResourceMock() |
1153
|
|
|
{ |
1154
|
|
|
return $this->getMock(ResourceInterface::class); |
|
|
|
|
1155
|
|
|
} |
1156
|
|
|
} |
1157
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: