1515use Symfony \Component \HttpFoundation \Request ;
1616use Symfony \Component \HttpKernel \Attribute \MapQueryString ;
1717use Symfony \Component \HttpKernel \Attribute \MapRequestPayload ;
18+ use Symfony \Component \HttpKernel \Attribute \ValueResolver ;
1819use Symfony \Component \HttpKernel \Controller \ArgumentResolver \RequestPayloadValueResolver ;
1920use Symfony \Component \HttpKernel \ControllerMetadata \ArgumentMetadata ;
2021use Symfony \Component \HttpKernel \Exception \HttpException ;
@@ -312,7 +313,7 @@ public static function provideMismatchedFormatContext(): iterable
312313 /**
313314 * @dataProvider provideValidationGroupsOnManyTypes
314315 */
315- public function testValidationGroupsPassed (mixed $ groups )
316+ public function testValidationGroupsPassed (string $ method , ValueResolver $ attribute )
316317 {
317318 $ input = ['price ' => '50 ' , 'title ' => 'A long title, so the validation passes ' ];
318319
@@ -323,10 +324,10 @@ public function testValidationGroupsPassed(mixed $groups)
323324 $ validator = (new ValidatorBuilder ())->enableAnnotationMapping ()->getValidator ();
324325 $ resolver = new RequestPayloadValueResolver ($ serializer , $ validator );
325326
326- $ request = Request::create ('/ ' , ' POST ' , $ input );
327+ $ request = Request::create ('/ ' , $ method , $ input );
327328
328329 $ argument = new ArgumentMetadata ('valid ' , RequestPayload::class, false , false , null , false , [
329- MapRequestPayload ::class => new MapRequestPayload (validationGroups: $ groups ) ,
330+ $ attribute ::class => $ attribute ,
330331 ]);
331332
332333 $ resolved = $ resolver ->resolve ($ request , $ argument );
@@ -338,7 +339,7 @@ public function testValidationGroupsPassed(mixed $groups)
338339 /**
339340 * @dataProvider provideValidationGroupsOnManyTypes
340341 */
341- public function testValidationGroupsNotPassed (mixed $ groups )
342+ public function testValidationGroupsNotPassed (string $ method , ValueResolver $ attribute )
342343 {
343344 $ input = ['price ' => '50 ' , 'title ' => 'Too short ' ];
344345
@@ -347,9 +348,9 @@ public function testValidationGroupsNotPassed(mixed $groups)
347348 $ resolver = new RequestPayloadValueResolver ($ serializer , $ validator );
348349
349350 $ argument = new ArgumentMetadata ('valid ' , RequestPayload::class, false , false , null , false , [
350- MapRequestPayload ::class => new MapRequestPayload (validationGroups: $ groups ) ,
351+ $ attribute ::class => $ attribute ,
351352 ]);
352- $ request = Request::create ('/ ' , ' POST ' , $ input );
353+ $ request = Request::create ('/ ' , $ method , $ input );
353354
354355 try {
355356 $ resolver ->resolve ($ request , $ argument );
@@ -364,11 +365,35 @@ public function testValidationGroupsNotPassed(mixed $groups)
364365
365366 public static function provideValidationGroupsOnManyTypes (): iterable
366367 {
367- yield 'validation group as string ' => ['strict ' ];
368+ yield 'request payload with validation group as string ' => [
369+ 'POST ' ,
370+ new MapRequestPayload (validationGroups: 'strict ' ),
371+ ];
368372
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+ ];
370382
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+ ];
372397 }
373398}
374399
0 commit comments