@@ -202,17 +202,50 @@ public function testRunReturnsLocalizedErrors(): void
202202
203203 public function testRunWithCustomErrors (): void
204204 {
205- $ data = ['foo ' => 'notanumber ' ];
206-
205+ $ data = [
206+ 'foo ' => 'notanumber ' ,
207+ 'bar ' => 'notanumber ' ,
208+ ];
207209 $ messages = [
208210 'foo ' => [
209211 'is_numeric ' => 'Nope. Not a number. ' ,
210212 ],
213+ 'bar ' => [
214+ 'is_numeric ' => 'No. Not a number. ' ,
215+ ],
211216 ];
217+ $ this ->validation ->setRules (['foo ' => 'is_numeric ' , 'bar ' => 'is_numeric ' ], $ messages );
218+ $ this ->validation ->run ($ data );
219+
220+ $ this ->assertSame ('Nope. Not a number. ' , $ this ->validation ->getError ('foo ' ));
221+ $ this ->assertSame ('No. Not a number. ' , $ this ->validation ->getError ('bar ' ));
222+ }
212223
213- $ this ->validation ->setRules (['foo ' => 'is_numeric ' ], $ messages );
224+ /**
225+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/6239
226+ */
227+ public function testSetRuleWithCustomErrors (): void
228+ {
229+ $ data = [
230+ 'foo ' => 'notanumber ' ,
231+ 'bar ' => 'notanumber ' ,
232+ ];
233+ $ this ->validation ->setRule (
234+ 'foo ' ,
235+ 'Foo ' ,
236+ ['foo ' => 'is_numeric ' ],
237+ ['is_numeric ' => 'Nope. Not a number. ' ]
238+ );
239+ $ this ->validation ->setRule (
240+ 'bar ' ,
241+ 'Bar ' ,
242+ ['bar ' => 'is_numeric ' ],
243+ ['is_numeric ' => 'Nope. Not a number. ' ]
244+ );
214245 $ this ->validation ->run ($ data );
246+
215247 $ this ->assertSame ('Nope. Not a number. ' , $ this ->validation ->getError ('foo ' ));
248+ $ this ->assertSame ('Nope. Not a number. ' , $ this ->validation ->getError ('bar ' ));
216249 }
217250
218251 public function testCheck (): void
0 commit comments