@@ -456,6 +456,51 @@ public function testClientCanSpecifyInputsToValidateWhenUsingControllerValidateW
456456 ]);
457457 }
458458
459+ public function testClientCanSpecifySimpleArrayWildcardToValidateWhenUsingControllerValidateWithPassingArrayOfRules ()
460+ {
461+ Route::post ('test-route ' , [PrecognitionTestController::class, 'methodWhereArrayRulesAreValidateViaControllerValidate ' ])
462+ ->middleware (PrecognitionInvokingController::class);
463+
464+ $ response = $ this ->postJson ('test-route ' , [
465+ 'raw_array ' => [123 , 'someString ' ],
466+ ], [
467+ 'Precognition ' => 'true ' ,
468+ 'Precognition-Validate-Only ' => 'raw_array.* ' ,
469+ ]);
470+
471+ $ response ->assertUnprocessable ();
472+ $ response ->assertHeaderMissing ('Precognition-Success ' );
473+ $ response ->assertJsonPath ('errors ' , [
474+ 'raw_array.0 ' => [
475+ 'The raw_array.0 field must be a string. ' ,
476+ ],
477+ ]);
478+ }
479+
480+ public function testClientCanSpecifyComplexArrayWildcardToValidateWhenUsingControllerValidateWithPassingArrayOfRules ()
481+ {
482+ Route::post ('test-route ' , [PrecognitionTestController::class, 'methodWhereArrayRulesAreValidateViaControllerValidate ' ])
483+ ->middleware (PrecognitionInvokingController::class);
484+
485+ $ response = $ this ->postJson ('test-route ' , [
486+ 'nested_array ' => [
487+ ['name ' => 123 ],
488+ ['name ' => 'someString ' ],
489+ ],
490+ ], [
491+ 'Precognition ' => 'true ' ,
492+ 'Precognition-Validate-Only ' => 'nested_array.*.name ' ,
493+ ]);
494+
495+ $ response ->assertUnprocessable ();
496+ $ response ->assertHeaderMissing ('Precognition-Success ' );
497+ $ response ->assertJsonPath ('errors ' , [
498+ 'nested_array.0.name ' => [
499+ 'The nested_array.0.name field must be a string. ' ,
500+ ],
501+ ]);
502+ }
503+
459504 public function testItAppendsAnAdditionalVaryHeaderInsteadOfReplacingAnyExistingVaryHeaders ()
460505 {
461506 Route::get ('test-route ' , function () {
@@ -1117,6 +1162,22 @@ public function methodWhereNestedRulesAreValidatedViaControllerValidate(Request
11171162 fail ();
11181163 }
11191164
1165+ public function methodWhereArrayRulesAreValidateViaControllerValidate (Request $ request )
1166+ {
1167+ precognitive (function () use ($ request ) {
1168+ $ this ->validate ($ request , [
1169+ 'nested_array ' => ['required ' , 'array ' , 'min:1 ' ],
1170+ 'nested_array.*.name ' => ['required ' , 'string ' ],
1171+ 'raw_array ' => ['required ' , 'array ' , 'min:1 ' ],
1172+ 'raw_array.* ' => ['required ' , 'string ' ],
1173+ ]);
1174+
1175+ fail ();
1176+ });
1177+
1178+ fail ();
1179+ }
1180+
11201181 public function methodWhereNestedRulesAreValidatedViaControllerValidateWith (Request $ request )
11211182 {
11221183 precognitive (function () {
0 commit comments