Skip to content

Commit 0b050d7

Browse files
committed
test: update cases to use compact errors
1 parent 1e35754 commit 0b050d7

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

tests/message.test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
$itemToValidate = ['data5' => 'wrong'];
2323

24-
expect(validator()->validate($itemToValidate, ['data5' => 'number|email']))->toBe(false);
24+
expect(validator()->validate($itemToValidate, ['data5' => 'expanded|number|email']))->toBe(false);
2525
expect(validator()->errors())->toHaveKey('data5');
2626
expect(validator()->errors()['data5'])->toContain('This is a custom message');
2727
expect(validator()->errors()['data5'])->toContain('This is another custom message');
@@ -32,7 +32,7 @@
3232

3333
$itemToValidate = ['data6' => 'wrong'];
3434

35-
expect(validator()->validate($itemToValidate, ['data6' => 'number']))->toBe(false);
35+
expect(validator()->validate($itemToValidate, ['data6' => 'number|expanded']))->toBe(false);
3636
expect(validator()->errors())->toHaveKey('data6');
3737
expect(validator()->errors()['data6'][0] ?? '')->toBe('This is a custom message for data6');
3838
});
@@ -44,7 +44,7 @@
4444

4545
expect(validator()->validate($itemToValidate, ['data2' => 'number']))->toBe(false);
4646
expect(validator()->errors())->toHaveKey('data2');
47-
expect(validator()->errors()['data2'][0] ?? '')->toBe('This is a custom message for Data2');
47+
expect(validator()->errors()['data2'] ?? '')->toBe('This is a custom message for Data2');
4848
});
4949

5050
test('message can be set for a rule with a custom placeholder and custom value', function () {
@@ -54,7 +54,7 @@
5454

5555
expect(validator()->validate($itemToValidate, ['data3' => 'number']))->toBe(false);
5656
expect(validator()->errors())->toHaveKey('data3');
57-
expect(validator()->errors()['data3'][0] ?? '')->toBe('This is a custom message for data3 with value wrong');
57+
expect(validator()->errors()['data3'] ?? '')->toBe('This is a custom message for data3 with value wrong');
5858
});
5959

6060
test('show error if no message is provided', function () {

tests/rules.test.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
expect(validator()->validate($dataToValidate1, ['item1' => 'anotherCustomRule']))->toBe(false);
5454

5555
expect(validator()->errors())->toHaveKey('item1');
56-
expect(validator()->errors()['item1'][0] ?? '')->toBe('This is a custom message');
56+
expect(validator()->errors()['item1'] ?? '')->toBe('This is a custom message');
5757
});
5858

5959
test('can add custom validation rules with closure and custom message with placeholder', function () {
@@ -66,7 +66,7 @@
6666
expect(validator()->validate($dataToValidate1, ['item2' => 'anotherCustomRule']))->toBe(false);
6767

6868
expect(validator()->errors())->toHaveKey('item2');
69-
expect(validator()->errors()['item2'][0] ?? '')->toBe('This is a custom message for item2');
69+
expect(validator()->errors()['item2'] ?? '')->toBe('This is a custom message for item2');
7070
});
7171

7272
test('can add custom validation rules with closure and custom message with placeholder and custom value', function () {
@@ -79,7 +79,7 @@
7979
expect(validator()->validate($dataToValidate1, ['item3' => 'anotherCustomRule']))->toBe(false);
8080

8181
expect(validator()->errors())->toHaveKey('item3');
82-
expect(validator()->errors()['item3'][0] ?? '')->toBe('This is a custom message for item3 with value not custom');
82+
expect(validator()->errors()['item3'] ?? '')->toBe('This is a custom message for item3 with value not custom');
8383
});
8484

8585
test('can add custom validation rules with regex and custom message', function () {
@@ -89,7 +89,7 @@
8989
expect(validator()->validate($dataToValidate1, ['item4' => 'mustHaveTheWordAvailable']))->toBe(false);
9090

9191
expect(validator()->errors())->toHaveKey('item4');
92-
expect(validator()->errors()['item4'][0] ?? '')->toBe('This is a custom message');
92+
expect(validator()->errors()['item4'] ?? '')->toBe('This is a custom message');
9393
});
9494

9595
test('can add custom validation rules with regex and custom message with placeholder', function () {
@@ -99,7 +99,7 @@
9999
expect(validator()->validate($dataToValidate1, ['item5' => 'mustHaveTheWordAvailable']))->toBe(false);
100100

101101
expect(validator()->errors())->toHaveKey('item5');
102-
expect(validator()->errors()['item5'][0] ?? '')->toBe('This is a custom message for item5');
102+
expect(validator()->errors()['item5'] ?? '')->toBe('This is a custom message for item5');
103103
});
104104

105105
test('can add custom validation rules with regex and custom message with placeholder and custom value', function () {
@@ -109,5 +109,5 @@
109109
expect(validator()->validate($dataToValidate1, ['item6' => 'mustHaveTheWordAvailable']))->toBe(false);
110110

111111
expect(validator()->errors())->toHaveKey('item6');
112-
expect(validator()->errors()['item6'][0] ?? '')->toBe('This is a custom message for item6 with value not in here');
112+
expect(validator()->errors()['item6'] ?? '')->toBe('This is a custom message for item6 with value not in here');
113113
});

0 commit comments

Comments
 (0)