summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--src/Validators/EmailValidator.php2
-rw-r--r--src/Validators/LenValidator.php2
-rw-r--r--src/Validators/RequiredValidator.php2
-rw-r--r--src/Validators/Validator.php2
-rw-r--r--tests/BouncerTest.php27
6 files changed, 29 insertions, 9 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ab7b0ed
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Bouncer
+
+An extensible validation library for your data with sane defaults. \ No newline at end of file
diff --git a/src/Validators/EmailValidator.php b/src/Validators/EmailValidator.php
index 5d69b5b..baca760 100644
--- a/src/Validators/EmailValidator.php
+++ b/src/Validators/EmailValidator.php
@@ -18,7 +18,7 @@ class EmailValidator implements Validator
* @param mixed $modifier
* @return boolean
*/
- public static function validate(string $value, mixed $modifier = null): bool
+ public static function validate(mixed $value, mixed $modifier = null): bool
{
return filter_var($value, FILTER_VALIDATE_EMAIL);
}
diff --git a/src/Validators/LenValidator.php b/src/Validators/LenValidator.php
index b4b5e2b..c92f7db 100644
--- a/src/Validators/LenValidator.php
+++ b/src/Validators/LenValidator.php
@@ -18,7 +18,7 @@ class LenValidator implements Validator
* @param mixed $modifier
* @return boolean
*/
- public static function validate(string $value, mixed $modifier = null): bool
+ public static function validate(mixed $value, mixed $modifier = null): bool
{
// If no modifier present then this validator will always validate.
if (!$modifier) {
diff --git a/src/Validators/RequiredValidator.php b/src/Validators/RequiredValidator.php
index 4cf6bfc..488a0ac 100644
--- a/src/Validators/RequiredValidator.php
+++ b/src/Validators/RequiredValidator.php
@@ -18,7 +18,7 @@ class RequiredValidator implements Validator
* @param mixed $modifier
* @return boolean
*/
- public static function validate(string $value, mixed $modifier = null): bool
+ public static function validate(mixed $value, mixed $modifier = null): bool
{
return isset($value) && $value !== '';
}
diff --git a/src/Validators/Validator.php b/src/Validators/Validator.php
index 11f2b01..2d3a948 100644
--- a/src/Validators/Validator.php
+++ b/src/Validators/Validator.php
@@ -4,6 +4,6 @@ namespace Askonomm\Bouncer\Validators;
interface Validator
{
- public static function validate(string $value, mixed $modifier = null): bool;
+ public static function validate(mixed $value, mixed $modifier = null): bool;
public static function composeError(string $field, mixed $modifier = null): string;
}
diff --git a/tests/BouncerTest.php b/tests/BouncerTest.php
index 9c14b66..473b476 100644
--- a/tests/BouncerTest.php
+++ b/tests/BouncerTest.php
@@ -15,7 +15,9 @@ test('Validate an incorrect e-mail address', function () {
$rules = ['email' => 'email'];
$bouncer = new Bouncer($fields, $rules);
- expect($bouncer->fails())->toBeTrue();
+ expect($bouncer->errors())->toBe([
+ 'email is not a valid e-mail address.'
+ ]);
});
test('Validate a correct length of string', function () {
@@ -31,7 +33,9 @@ test('Validate an incorrect length of string', function () {
$rules = ['string' => 'len:15'];
$bouncer = new Bouncer($fields, $rules);
- expect($bouncer->fails())->toBeTrue();
+ expect($bouncer->errors())->toBe([
+ 'string is shorter than the required 15 characters.'
+ ]);
});
test('Validate a correct required string', function () {
@@ -43,9 +47,22 @@ test('Validate a correct required string', function () {
});
test('Validate an incorrect required string', function () {
- $fields = ['string' => ''];
- $rules = ['string' => 'required'];
+ $fields = [
+ 'empty-string' => '',
+ 'null-value' => null,
+ 'false-value' => false,
+ ];
+
+ $rules = [
+ 'empty-string' => 'required',
+ 'null-value' => 'required',
+ 'false-value' => 'required',
+ ];
+
$bouncer = new Bouncer($fields, $rules);
- expect($bouncer->fails())->toBeTrue();
+ expect($bouncer->errors())->toBe([
+ 'empty-string is required.',
+ 'null-value is required.',
+ ]);
});