Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not accept whitespace by default in "Digit" rule
The "Digit" rule is meant to validate digits. However, by default, it also considers any whitespace character (spaces, new lines, tabs, etc) as valid. Since the rule also accepts a list of characters to ignore during the validation it seemed logical to me to leave the responsibility of allowing whitespace characters on the hands of the one who uses the rule. The messages of the exception are not really consistent, this commit will also fix that. It's also clear that the "AbstractCtypeRule" is an unnecessary overhead since it is only a proxy for "AbstractFilterRule". That one can and should even be removed after this commit is applied especially because this commit will also remove the method "filterWhiteSpaceOption" which is the only substantial difference between "AbstractCtypeRule" and "AbstractFilterRule". This commit will also apply our guidelines to the "Digit" rule since we want to do that to all the rules we have. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
- Loading branch information
1 parent
27bd5d2
commit 9283c8e
Showing
11 changed files
with
151 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--FILE-- | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
use Respect\Validation\Exceptions\DigitException; | ||
use Respect\Validation\Exceptions\NestedValidationException; | ||
use Respect\Validation\Validator as v; | ||
|
||
try { | ||
v::digit()->check('abc'); | ||
} catch (DigitException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::digit('-')->check('a-b'); | ||
} catch (DigitException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::digit())->check('123'); | ||
} catch (DigitException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::digit('-'))->check('1-3'); | ||
} catch (DigitException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::digit()->assert('abc'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::digit('-')->assert('a-b'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::digit())->assert('123'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::digit('-'))->assert('1-3'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
?> | ||
--EXPECT-- | ||
"abc" must contain only digits (0-9) | ||
"a-b" must contain only digits (0-9) and "-" | ||
"123" must not contain digits (0-9) | ||
"1-3" must not contain digits (0-9) and "-" | ||
- "abc" must contain only digits (0-9) | ||
- "a-b" must contain only digits (0-9) and "-" | ||
- "123" must not contain digits (0-9) | ||
- "1-3" must not contain digits (0-9) and "-" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters