@@ -74,6 +74,7 @@ public function testResolve(): void
74
74
75
75
],
76
76
],
77
+ 'test_validation_custom_attributes ' => 'test ' ,
77
78
], [], $ this ->resolveInfoMock ());
78
79
}
79
80
@@ -117,7 +118,8 @@ public function testValidationError(): void
117
118
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.otherValue ' ));
118
119
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.nest ' ));
119
120
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.list ' ));
120
- self ::assertCount (6 , $ messages ->all ());
121
+ self ::assertTrue ($ messages ->has ('test_validation_custom_attributes ' ));
122
+ self ::assertCount (7 , $ messages ->all ());
121
123
}
122
124
123
125
public function testWithInput (): void
@@ -154,7 +156,8 @@ public function testWithInput(): void
154
156
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.otherValue ' ));
155
157
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.nest ' ));
156
158
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.list ' ));
157
- self ::assertCount (6 , $ messages ->all ());
159
+ self ::assertTrue ($ messages ->has ('test_validation_custom_attributes ' ));
160
+ self ::assertCount (7 , $ messages ->all ());
158
161
}
159
162
160
163
public function testWithEmptyInput (): void
@@ -182,7 +185,8 @@ public function testWithEmptyInput(): void
182
185
self ::assertTrue ($ messages ->has ('test_with_rules ' ));
183
186
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object ' ));
184
187
self ::assertTrue ($ messages ->has ('test_with_rules_closure ' ));
185
- self ::assertCount (4 , $ messages ->all ());
188
+ self ::assertTrue ($ messages ->has ('test_validation_custom_attributes ' ));
189
+ self ::assertCount (5 , $ messages ->all ());
186
190
}
187
191
188
192
public function testWithInputDepthOne (): void
@@ -212,7 +216,8 @@ public function testWithInputDepthOne(): void
212
216
213
217
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object ' ));
214
218
self ::assertTrue ($ messages ->has ('test_with_rules_closure ' ));
215
- self ::assertCount (3 , $ messages ->all ());
219
+ self ::assertTrue ($ messages ->has ('test_validation_custom_attributes ' ));
220
+ self ::assertCount (4 , $ messages ->all ());
216
221
}
217
222
218
223
public function testWithInputWithEmptyInputObjects (): void
@@ -245,6 +250,8 @@ public function testWithInputWithEmptyInputObjects(): void
245
250
246
251
self ::assertTrue ($ messages ->has ('test_with_rules ' ));
247
252
253
+ self ::assertTrue ($ messages ->has ('test_validation_custom_attributes ' ));
254
+
248
255
self ::assertTrue ($ messages ->has ('test_with_rules_nullable_input_object.otherValue ' ));
249
256
self ::assertTrue ($ messages ->has ('test_with_rules_nullable_input_object.val ' ));
250
257
self ::assertTrue ($ messages ->has ('test_with_rules_nullable_input_object.nest ' ));
@@ -253,7 +260,7 @@ public function testWithInputWithEmptyInputObjects(): void
253
260
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.val ' ));
254
261
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.nest ' ));
255
262
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object.list ' ));
256
- self ::assertCount (12 , $ messages ->all ());
263
+ self ::assertCount (13 , $ messages ->all ());
257
264
}
258
265
259
266
public function testWithEmptyArrayOfInputsObjects (): void
@@ -282,7 +289,8 @@ public function testWithEmptyArrayOfInputsObjects(): void
282
289
self ::assertTrue ($ messages ->has ('test_with_rules ' ));
283
290
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_input_object ' ));
284
291
self ::assertTrue ($ messages ->has ('test_with_rules_closure ' ));
285
- self ::assertCount (4 , $ messages ->all ());
292
+ self ::assertTrue ($ messages ->has ('test_validation_custom_attributes ' ));
293
+ self ::assertCount (5 , $ messages ->all ());
286
294
}
287
295
288
296
public function testWithArrayOfInputsObjects (): void
@@ -319,7 +327,8 @@ public function testWithArrayOfInputsObjects(): void
319
327
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_list_of_non_nullable_input_object.0.otherValue ' ));
320
328
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_list_of_non_nullable_input_object.0.nest ' ));
321
329
self ::assertTrue ($ messages ->has ('test_with_rules_non_nullable_list_of_non_nullable_input_object.0.list ' ));
322
- self ::assertCount (7 , $ messages ->all ());
330
+ self ::assertTrue ($ messages ->has ('test_validation_custom_attributes ' ));
331
+ self ::assertCount (8 , $ messages ->all ());
323
332
}
324
333
325
334
public function testCustomValidationErrorMessages (): void
@@ -356,6 +365,25 @@ public function testCustomValidationErrorMessages(): void
356
365
);
357
366
}
358
367
368
+ public function testCustomValidationAttributes (): void
369
+ {
370
+ $ class = $ this ->getFieldClass ();
371
+ $ field = new $ class ();
372
+ $ attributes = $ field ->getAttributes ();
373
+
374
+ /** @var ValidationError $exception */
375
+ $ exception = null ;
376
+
377
+ try {
378
+ $ attributes ['resolve ' ](null , [], [], $ this ->resolveInfoMock ());
379
+ } catch (ValidationError $ exception ) {
380
+ }
381
+
382
+ $ messages = $ exception ->getValidatorMessages ();
383
+
384
+ self ::assertEquals ('The custom attribute field is required. ' , $ messages ->first ('test_validation_custom_attributes ' ));
385
+ }
386
+
359
387
public function testRuleCallbackArgumentsMatchesTheInput (): void
360
388
{
361
389
$ this ->expectException (ValidationError::class);
0 commit comments