Skip to content
Permalink
Browse files

Validators: added 'file', 'directory', 'class', 'interface' & mixed

  • Loading branch information...
dg committed Mar 12, 2019
1 parent 2f751f1 commit ac90a28bdb1187200d12db353db99e4bc001b5d3
Showing with 44 additions and 0 deletions.
  1. +12 −0 src/Utils/Validators.php
  2. +32 −0 tests/Utils/Validators.is().phpt
@@ -37,6 +37,7 @@ class Validators
'callable' => [__CLASS__, 'isCallable'],
'iterable' => 'is_iterable',
'list' => [Arrays::class, 'isList'],
'mixed' => [__CLASS__, 'isMixed'],
'none' => [__CLASS__, 'isNone'],
'number' => [__CLASS__, 'isNumber'],
'numeric' => [__CLASS__, 'isNumeric'],
@@ -60,6 +61,10 @@ class Validators
'url' => [__CLASS__, 'isUrl'],
// environment validation
'class' => 'class_exists',
'interface' => 'interface_exists',
'directory' => 'is_dir',
'file' => 'is_file',
'type' => [__CLASS__, 'isType'],
];
@@ -236,6 +241,13 @@ public static function isNone($value): bool
}
/** @internal */
public static function isMixed(): bool
{
return true;
}
/**
* Finds whether a variable is a zero-based integer indexed array.
*/
@@ -170,6 +170,12 @@ test(function () {
});
test(function () {
Assert::true(Validators::is([], 'mixed'));
Assert::true(Validators::is(null, 'mixed'));
});
test(function () {
Assert::false(Validators::is('', 'email'));
Assert::false(Validators::is(false, 'email'));
@@ -321,6 +327,32 @@ test(function () {
});
test(function () {
Assert::true(Validators::is('rimmer', 'class'));
Assert::false(Validators::is('kryton', 'class'));
Assert::false(Validators::is('1', 'class'));
});
test(function () {
Assert::false(Validators::is('rimmer', 'interface'));
Assert::true(Validators::is('kryton', 'interface'));
Assert::false(Validators::is('1', 'interface'));
});
test(function () {
Assert::true(Validators::is(__FILE__, 'file'));
Assert::false(Validators::is(__FILE__ . 'xx', 'class'));
});
test(function () {
Assert::true(Validators::is(__DIR__, 'directory'));
Assert::false(Validators::is(__DIR__ . 'xx', 'directory'));
});
test(function () {
Assert::true(Validators::is('Item', 'identifier'));
Assert::false(Validators::is('0Item', 'identifier'));

0 comments on commit ac90a28

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.