respect-validation/tests/integration/rules/json.phpt
Henrique Moody cc20a442a1
Apply "SlevomatCodingStandard.TypeHints.DeclareStrictTypes"
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-02-09 14:11:12 +01:00

42 lines
1 KiB
PHP

--CREDITS--
Danilo Benevides <danilobenevides01@gmail.com>
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Exceptions\JsonException;
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Validator as v;
try {
v::json()->check(false);
} catch (JsonException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::not(v::json())->check('{"foo": "bar", "number":1}');
} catch (JsonException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::json()->assert(new \stdClass());
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
try {
v::not(v::json())->assert('{}');
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
?>
--EXPECT--
`FALSE` must be a valid JSON string
"{\"foo\": \"bar\", \"number\":1}" must not be a valid JSON string
- `[object] (stdClass: { })` must be a valid JSON string
- "{}" must not be a valid JSON string