2018-11-30 09:25:42 +01:00
|
|
|
--CREDITS--
|
|
|
|
Henrique Moody <henriquemoody@gmail.com>
|
2018-08-19 20:09:32 +02:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2019-02-09 11:44:33 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-19 20:09:32 +02:00
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
|
|
|
use Respect\Validation\Exceptions\NestedValidationException;
|
|
|
|
use Respect\Validation\Exceptions\SfException;
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
use Symfony\Component\Validator\Constraints\Collection;
|
|
|
|
use Symfony\Component\Validator\Constraints\Email;
|
|
|
|
use Symfony\Component\Validator\Constraints\IsNull;
|
|
|
|
|
|
|
|
try {
|
|
|
|
v::sf(new IsNull())->check('something');
|
|
|
|
} catch (SfException $exception) {
|
2020-07-21 22:54:41 +02:00
|
|
|
echo $exception->getMessage() . PHP_EOL;
|
2018-08-19 20:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
v::not(v::sf(new IsNull()))->check(null);
|
|
|
|
} catch (SfException $exception) {
|
2020-07-21 22:54:41 +02:00
|
|
|
echo $exception->getMessage() . PHP_EOL;
|
2018-08-19 20:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
v::sf(new Email())->assert('not-null');
|
|
|
|
} catch (NestedValidationException $exception) {
|
2020-07-21 22:54:41 +02:00
|
|
|
echo $exception->getFullMessage() . PHP_EOL;
|
2018-08-19 20:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
v::not(v::sf(new Email()))->assert('example@example.com');
|
|
|
|
} catch (NestedValidationException $exception) {
|
2020-07-21 22:54:41 +02:00
|
|
|
echo $exception->getFullMessage() . PHP_EOL;
|
2018-08-19 20:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
v::sf(
|
|
|
|
new Collection([
|
|
|
|
'first' => new IsNull(),
|
|
|
|
'second' => new Email(),
|
|
|
|
])
|
|
|
|
)->check(['second' => 'not-email']);
|
|
|
|
} catch (SfException $exception) {
|
|
|
|
echo $exception->getMessage();
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECTF--
|
|
|
|
This value should be null.
|
|
|
|
`NULL` must not be valid for `[object] (Symfony\Component\Validator\Constraints\IsNull: { %s })`
|
|
|
|
- This value is not a valid email address.
|
|
|
|
- "example@example.com" must not be valid for `[object] (Symfony\Component\Validator\Constraints\Email: { %s })`
|
|
|
|
Array[first]:
|
|
|
|
This field is missing. (code %s)
|
|
|
|
Array[second]:
|
|
|
|
This value is not a valid email address. (code %s)
|