15
15
use Symfony \Component \HttpFoundation \Request ;
16
16
use Symfony \Component \HttpKernel \Attribute \MapQueryString ;
17
17
use Symfony \Component \HttpKernel \Attribute \MapRequestPayload ;
18
+ use Symfony \Component \HttpKernel \Attribute \ValueResolver ;
18
19
use Symfony \Component \HttpKernel \Controller \ArgumentResolver \RequestPayloadValueResolver ;
19
20
use Symfony \Component \HttpKernel \ControllerMetadata \ArgumentMetadata ;
20
21
use Symfony \Component \HttpKernel \Exception \HttpException ;
@@ -312,7 +313,7 @@ public static function provideMismatchedFormatContext(): iterable
312
313
/**
313
314
* @dataProvider provideValidationGroupsOnManyTypes
314
315
*/
315
- public function testValidationGroupsPassed (mixed $ groups )
316
+ public function testValidationGroupsPassed (string $ method , ValueResolver $ attribute )
316
317
{
317
318
$ input = ['price ' => '50 ' , 'title ' => 'A long title, so the validation passes ' ];
318
319
@@ -323,10 +324,10 @@ public function testValidationGroupsPassed(mixed $groups)
323
324
$ validator = (new ValidatorBuilder ())->enableAnnotationMapping ()->getValidator ();
324
325
$ resolver = new RequestPayloadValueResolver ($ serializer , $ validator );
325
326
326
- $ request = Request::create ('/ ' , ' POST ' , $ input );
327
+ $ request = Request::create ('/ ' , $ method , $ input );
327
328
328
329
$ argument = new ArgumentMetadata ('valid ' , RequestPayload::class, false , false , null , false , [
329
- MapRequestPayload ::class => new MapRequestPayload (validationGroups: $ groups ) ,
330
+ $ attribute ::class => $ attribute ,
330
331
]);
331
332
332
333
$ resolved = $ resolver ->resolve ($ request , $ argument );
@@ -338,7 +339,7 @@ public function testValidationGroupsPassed(mixed $groups)
338
339
/**
339
340
* @dataProvider provideValidationGroupsOnManyTypes
340
341
*/
341
- public function testValidationGroupsNotPassed (mixed $ groups )
342
+ public function testValidationGroupsNotPassed (string $ method , ValueResolver $ attribute )
342
343
{
343
344
$ input = ['price ' => '50 ' , 'title ' => 'Too short ' ];
344
345
@@ -347,9 +348,9 @@ public function testValidationGroupsNotPassed(mixed $groups)
347
348
$ resolver = new RequestPayloadValueResolver ($ serializer , $ validator );
348
349
349
350
$ argument = new ArgumentMetadata ('valid ' , RequestPayload::class, false , false , null , false , [
350
- MapRequestPayload ::class => new MapRequestPayload (validationGroups: $ groups ) ,
351
+ $ attribute ::class => $ attribute ,
351
352
]);
352
- $ request = Request::create ('/ ' , ' POST ' , $ input );
353
+ $ request = Request::create ('/ ' , $ method , $ input );
353
354
354
355
try {
355
356
$ resolver ->resolve ($ request , $ argument );
@@ -364,11 +365,35 @@ public function testValidationGroupsNotPassed(mixed $groups)
364
365
365
366
public static function provideValidationGroupsOnManyTypes (): iterable
366
367
{
367
- yield 'validation group as string ' => ['strict ' ];
368
+ yield 'request payload with validation group as string ' => [
369
+ 'POST ' ,
370
+ new MapRequestPayload (validationGroups: 'strict ' ),
371
+ ];
368
372
369
- yield 'validation group as array ' => [['strict ' ]];
373
+ yield 'request payload with validation group as array ' => [
374
+ 'POST ' ,
375
+ new MapRequestPayload (validationGroups: ['strict ' ]),
376
+ ];
377
+
378
+ yield 'request payload with validation group as GroupSequence ' => [
379
+ 'POST ' ,
380
+ new MapRequestPayload (validationGroups: new Assert \GroupSequence (['strict ' ])),
381
+ ];
370
382
371
- yield 'validation group as GroupSequence ' => [new Assert \GroupSequence (['strict ' ])];
383
+ yield 'query with validation group as string ' => [
384
+ 'GET ' ,
385
+ new MapQueryString (validationGroups: 'strict ' ),
386
+ ];
387
+
388
+ yield 'query with validation group as array ' => [
389
+ 'GET ' ,
390
+ new MapQueryString (validationGroups: ['strict ' ]),
391
+ ];
392
+
393
+ yield 'query with validation group as GroupSequence ' => [
394
+ 'GET ' ,
395
+ new MapQueryString (validationGroups: new Assert \GroupSequence (['strict ' ])),
396
+ ];
372
397
}
373
398
}
374
399
0 commit comments