mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 16:52:16 +02:00
Make "NotEmpty" a final class
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
7b53d54931
commit
51f157605d
|
@ -23,7 +23,7 @@ use function trim;
|
|||
* @author Bram Van der Sype <bram.vandersype@gmail.com>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
*/
|
||||
class NotEmpty extends AbstractRule
|
||||
final class NotEmpty extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
|
|
@ -21,7 +21,7 @@ use function is_null;
|
|||
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
*/
|
||||
final class NullType extends NotEmpty
|
||||
final class NullType extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
|
|
@ -8,67 +8,51 @@ declare(strict_types=1);
|
|||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\AllOfException;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Exceptions\NotEmptyException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
$notEmptyValues = [
|
||||
'a',
|
||||
1,
|
||||
1.0,
|
||||
];
|
||||
|
||||
//Check not empty values
|
||||
foreach ($notEmptyValues as $value) {
|
||||
v::notEmpty()->assert($value);
|
||||
v::notEmpty()->check($value);
|
||||
}
|
||||
|
||||
//Check a not empty array
|
||||
v::notEmpty()->assert([1]);
|
||||
v::notEmpty()->check([1]);
|
||||
|
||||
try {
|
||||
v::notEmpty()->check(null);
|
||||
} catch (NotEmptyException $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::notEmpty()->assert('');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::notEmpty()->setName('Field')->check(null);
|
||||
} catch (NotEmptyException $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::notEmpty()->setName('Field')->assert('');
|
||||
} catch (AllOfException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::notEmpty())->check(1);
|
||||
} catch (NotEmptyException $e) {
|
||||
echo $e->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::notEmpty()->assert('');
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::notEmpty()->setName('Field')->assert('');
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::notEmpty())->assert([1]);
|
||||
} catch (AllOfException $e) {
|
||||
} catch (NestedValidationException $e) {
|
||||
echo $e->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
The value must not be empty
|
||||
- The value must not be empty
|
||||
Field must not be empty
|
||||
- Field must not be empty
|
||||
1 must be empty
|
||||
- The value must not be empty
|
||||
- Field must not be empty
|
||||
- `{ 1 }` must be empty
|
||||
|
|
Loading…
Reference in a new issue