Make "NotEmpty" a final class

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2019-04-05 20:28:58 +02:00
parent 7b53d54931
commit 51f157605d
No known key found for this signature in database
GPG key ID: 221E9281655813A6
3 changed files with 18 additions and 34 deletions

View file

@ -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}

View file

@ -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}

View file

@ -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