From 0b050d7150f74239322020f68698f6fbe142738a Mon Sep 17 00:00:00 2001 From: mychidarko Date: Sat, 9 Nov 2024 03:39:36 +0000 Subject: [PATCH] test: update cases to use compact errors --- tests/message.test.php | 8 ++++---- tests/rules.test.php | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/message.test.php b/tests/message.test.php index 93291a2..04e3ce3 100644 --- a/tests/message.test.php +++ b/tests/message.test.php @@ -21,7 +21,7 @@ $itemToValidate = ['data5' => 'wrong']; - expect(validator()->validate($itemToValidate, ['data5' => 'number|email']))->toBe(false); + expect(validator()->validate($itemToValidate, ['data5' => 'expanded|number|email']))->toBe(false); expect(validator()->errors())->toHaveKey('data5'); expect(validator()->errors()['data5'])->toContain('This is a custom message'); expect(validator()->errors()['data5'])->toContain('This is another custom message'); @@ -32,7 +32,7 @@ $itemToValidate = ['data6' => 'wrong']; - expect(validator()->validate($itemToValidate, ['data6' => 'number']))->toBe(false); + expect(validator()->validate($itemToValidate, ['data6' => 'number|expanded']))->toBe(false); expect(validator()->errors())->toHaveKey('data6'); expect(validator()->errors()['data6'][0] ?? '')->toBe('This is a custom message for data6'); }); @@ -44,7 +44,7 @@ expect(validator()->validate($itemToValidate, ['data2' => 'number']))->toBe(false); expect(validator()->errors())->toHaveKey('data2'); - expect(validator()->errors()['data2'][0] ?? '')->toBe('This is a custom message for Data2'); + expect(validator()->errors()['data2'] ?? '')->toBe('This is a custom message for Data2'); }); test('message can be set for a rule with a custom placeholder and custom value', function () { @@ -54,7 +54,7 @@ expect(validator()->validate($itemToValidate, ['data3' => 'number']))->toBe(false); expect(validator()->errors())->toHaveKey('data3'); - expect(validator()->errors()['data3'][0] ?? '')->toBe('This is a custom message for data3 with value wrong'); + expect(validator()->errors()['data3'] ?? '')->toBe('This is a custom message for data3 with value wrong'); }); test('show error if no message is provided', function () { diff --git a/tests/rules.test.php b/tests/rules.test.php index 22877e1..8144cb8 100644 --- a/tests/rules.test.php +++ b/tests/rules.test.php @@ -53,7 +53,7 @@ expect(validator()->validate($dataToValidate1, ['item1' => 'anotherCustomRule']))->toBe(false); expect(validator()->errors())->toHaveKey('item1'); - expect(validator()->errors()['item1'][0] ?? '')->toBe('This is a custom message'); + expect(validator()->errors()['item1'] ?? '')->toBe('This is a custom message'); }); test('can add custom validation rules with closure and custom message with placeholder', function () { @@ -66,7 +66,7 @@ expect(validator()->validate($dataToValidate1, ['item2' => 'anotherCustomRule']))->toBe(false); expect(validator()->errors())->toHaveKey('item2'); - expect(validator()->errors()['item2'][0] ?? '')->toBe('This is a custom message for item2'); + expect(validator()->errors()['item2'] ?? '')->toBe('This is a custom message for item2'); }); test('can add custom validation rules with closure and custom message with placeholder and custom value', function () { @@ -79,7 +79,7 @@ expect(validator()->validate($dataToValidate1, ['item3' => 'anotherCustomRule']))->toBe(false); expect(validator()->errors())->toHaveKey('item3'); - expect(validator()->errors()['item3'][0] ?? '')->toBe('This is a custom message for item3 with value not custom'); + expect(validator()->errors()['item3'] ?? '')->toBe('This is a custom message for item3 with value not custom'); }); test('can add custom validation rules with regex and custom message', function () { @@ -89,7 +89,7 @@ expect(validator()->validate($dataToValidate1, ['item4' => 'mustHaveTheWordAvailable']))->toBe(false); expect(validator()->errors())->toHaveKey('item4'); - expect(validator()->errors()['item4'][0] ?? '')->toBe('This is a custom message'); + expect(validator()->errors()['item4'] ?? '')->toBe('This is a custom message'); }); test('can add custom validation rules with regex and custom message with placeholder', function () { @@ -99,7 +99,7 @@ expect(validator()->validate($dataToValidate1, ['item5' => 'mustHaveTheWordAvailable']))->toBe(false); expect(validator()->errors())->toHaveKey('item5'); - expect(validator()->errors()['item5'][0] ?? '')->toBe('This is a custom message for item5'); + expect(validator()->errors()['item5'] ?? '')->toBe('This is a custom message for item5'); }); test('can add custom validation rules with regex and custom message with placeholder and custom value', function () { @@ -109,5 +109,5 @@ expect(validator()->validate($dataToValidate1, ['item6' => 'mustHaveTheWordAvailable']))->toBe(false); expect(validator()->errors())->toHaveKey('item6'); - expect(validator()->errors()['item6'][0] ?? '')->toBe('This is a custom message for item6 with value not in here'); + expect(validator()->errors()['item6'] ?? '')->toBe('This is a custom message for item6 with value not in here'); });