@@ -257,6 +257,70 @@ public function testForEachCallbacksCanContainMultipleRegexRules()
257
257
], $ v ->getMessageBag ()->toArray ());
258
258
}
259
259
260
+ public function testConditionalRulesCanBeAddedToForEachWithAssociativeArray ()
261
+ {
262
+ $ v = new Validator (
263
+ $ this ->getIlluminateArrayTranslator (),
264
+ [
265
+ 'foo ' => [
266
+ ['bar ' => true ],
267
+ ['bar ' => false ],
268
+ ],
269
+ ],
270
+ [
271
+ 'foo.* ' => Rule::forEach (fn (mixed $ value , string $ attribute ) => [
272
+ 'bar ' => Rule::when (true , ['accepted ' ], ['declined ' ]),
273
+ ]),
274
+ ]
275
+ );
276
+
277
+ $ this ->assertEquals ([
278
+ 'foo.1.bar ' => ['validation.accepted ' ],
279
+ ], $ v ->getMessageBag ()->toArray ());
280
+ }
281
+ public function testConditionalRulesCanBeAddedToForEachWithList ()
282
+ {
283
+ $ v = new Validator (
284
+ $ this ->getIlluminateArrayTranslator (),
285
+ [
286
+ 'foo ' => [
287
+ ['bar ' => true ],
288
+ ['bar ' => false ],
289
+ ],
290
+ ],
291
+ [
292
+ 'foo.*.bar ' => Rule::forEach (fn (mixed $ value , string $ attribute ) => [
293
+ Rule::when (true , ['accepted ' ], ['declined ' ]),
294
+ ]),
295
+ ]);
296
+
297
+ $ this ->assertEquals ([
298
+ 'foo.1.bar ' => ['validation.accepted ' ],
299
+ ], $ v ->getMessageBag ()->toArray ());
300
+
301
+ }
302
+
303
+ public function testConditionalRulesCanBeAddedToForEachWithObject ()
304
+ {
305
+ $ v = new Validator (
306
+ $ this ->getIlluminateArrayTranslator (),
307
+ [
308
+ 'foo ' => [
309
+ ['bar ' => true ],
310
+ ['bar ' => false ],
311
+ ],
312
+ ],
313
+ [
314
+ 'foo.*.bar ' => Rule::forEach (fn (mixed $ value , string $ attribute ) =>
315
+ Rule::when (true , ['accepted ' ], ['declined ' ]),
316
+ ),
317
+ ]);
318
+
319
+ $ this ->assertEquals ([
320
+ 'foo.1.bar ' => ['validation.accepted ' ],
321
+ ], $ v ->getMessageBag ()->toArray ());
322
+ }
323
+
260
324
protected function getTranslator ()
261
325
{
262
326
return m::mock (TranslatorContract::class);
0 commit comments