From 57518b03cbf19b8a714d6fcb573f71cb921005e3 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 25 Sep 2023 17:29:52 +0300 Subject: Implement `$fieldNames`, a way to overwrite field names to be more human friendly in error messages. --- tests/HirdTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/HirdTest.php b/tests/HirdTest.php index 9e49467..35f4895 100644 --- a/tests/HirdTest.php +++ b/tests/HirdTest.php @@ -88,3 +88,21 @@ test('Validate an incorrect correct date format', function () { 'date does not match the required date format Y-m-d H:i:s.', ]); }); + +test('Validate using a overwritten field name', function () { + $fields = ['date' => '2020-09-17 15:00']; + $fieldNames = ['date' => 'Date']; + $rules = ['date' => 'date-format:Y-m-d H:i:s']; + + $hird = new Hird( + fields: $fields, + rules: $rules, + fieldNames: $fieldNames + ); + + $hird->fails(); + + expect($hird->errors())->toBe([ + 'Date does not match the required date format Y-m-d H:i:s.', + ]); +}); -- cgit v1.2.3