Skip to content

Commit

Permalink
test: update cases to use compact errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Nov 9, 2024
1 parent 1e35754 commit 0b050d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions tests/message.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
});
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down
12 changes: 6 additions & 6 deletions tests/rules.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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');
});

0 comments on commit 0b050d7

Please sign in to comment.