diff options
| author | Asko Nomm <asko@bien.ee> | 2022-02-23 18:01:02 +0100 |
|---|---|---|
| committer | Asko Nomm <asko@bien.ee> | 2022-02-23 18:01:02 +0100 |
| commit | eedb71682cc1f62bc9789945c952194e2f5efa03 (patch) | |
| tree | 573a2265f2f3aaa38eaf30fa3a5d56eea8a3b57d /tests/HirdTest.php | |
| parent | 6b5b238e838116560e298deff4c9bcab140ac050 (diff) | |
Rename Bouncer to Hird
Diffstat (limited to 'tests/HirdTest.php')
| -rw-r--r-- | tests/HirdTest.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/HirdTest.php b/tests/HirdTest.php new file mode 100644 index 0000000..273eff6 --- /dev/null +++ b/tests/HirdTest.php @@ -0,0 +1,68 @@ +<?php + +use Askonomm\Hird\Hird; + +test('Validate a correct e-mail address', function () { + $fields = ['email' => 'asko@bien.ee']; + $rules = ['email' => 'email']; + $hird = new Hird($fields, $rules); + + expect($hird->fails())->toBeFalse(); +}); + +test('Validate an incorrect e-mail address', function () { + $fields = ['email' => 'this-is-not-right']; + $rules = ['email' => 'email']; + $hird = new Hird($fields, $rules); + + expect($hird->errors())->toBe([ + 'email is not a valid e-mail address.' + ]); +}); + +test('Validate a correct length of string', function () { + $fields = ['string' => 'i-am-fine-as-i-am-long']; + $rules = ['string' => 'len:8']; + $hird = new Hird($fields, $rules); + + expect($hird->fails())->toBeFalse(); +}); + +test('Validate an incorrect length of string', function () { + $fields = ['string' => 'i-am-short']; + $rules = ['string' => 'len:15']; + $hird = new Hird($fields, $rules); + + expect($hird->errors())->toBe([ + 'string is shorter than the required 15 characters.' + ]); +}); + +test('Validate a correct required string', function () { + $fields = ['string' => 'i-am-required']; + $rules = ['string' => 'required']; + $hird = new Hird($fields, $rules); + + expect($hird->fails())->toBeFalse(); +}); + +test('Validate an incorrect required string', function () { + $fields = [ + 'empty-string' => '', + 'null-value' => null, + 'false-value' => false, + ]; + + $rules = [ + 'empty-string' => 'required', + 'null-value' => 'required', + 'false-value' => 'required', + ]; + + $hird = new Hird($fields, $rules); + + expect($hird->errors())->toBe([ + 'empty-string is required.', + 'null-value is required.', + ]); +}); |
