-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit Test: fix bug on unit test using pest issues
- Loading branch information
1 parent
367e326
commit b0c7ea8
Showing
3 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
use BlakvGhost\PHPValidator\LangManager; | ||
use BlakvGhost\PHPValidator\Rules\EmailRule; | ||
use BlakvGhost\PHPValidator\Rules\MaxLengthRule; | ||
use BlakvGhost\PHPValidator\Rules\RequiredRule; | ||
use BlakvGhost\PHPValidator\Rules\StringRule; | ||
|
||
|
||
it('validates required rule successfully', function () { | ||
$validator = new RequiredRule([]); | ||
|
||
expect($validator->passes('field', 'value', ['field' => 'value']))->toBeTrue(); | ||
expect($validator->passes('field', '', []))->toBeFalse(); | ||
|
||
expect($validator->message())->toBe( | ||
LangManager::getTranslation('validation.required_rule', ['attribute' => 'field']) | ||
); | ||
}); | ||
|
||
it('validates max length rule successfully', function () { | ||
$validator = new MaxLengthRule([5]); | ||
|
||
expect($validator->passes('field', 'value', []))->toBeTrue(); | ||
expect($validator->passes('field', 'toolongvalue', []))->toBeFalse(); | ||
|
||
expect($validator->message())->toBe( | ||
LangManager::getTranslation('validation.max_length_rule', ['attribute' => 'field', 'max' => 5]) | ||
); | ||
}); | ||
|
||
it('validates email rule successfully', function () { | ||
$validator = new EmailRule([]); | ||
|
||
expect($validator->passes('email', 'test@example.com', []))->toBeTrue(); | ||
expect($validator->passes('email', 'invalid-email', []))->toBeFalse(); | ||
|
||
expect($validator->message())->toBe( | ||
LangManager::getTranslation('validation.email_rule', ['attribute' => 'email']) | ||
); | ||
}); | ||
|
||
it('validates string rule successfully', function () { | ||
$validator = new StringRule([]); | ||
|
||
expect($validator->passes('field', 'value', []))->toBeTrue(); | ||
expect($validator->passes('field', 5, []))->toBeFalse(); | ||
|
||
expect($validator->message())->toBe( | ||
LangManager::getTranslation('validation.string_rule', ['attribute' => 'field']) | ||
); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters