respect-validation/tests/integration/rules/stringVal.phpt
Danilo Correa e832a99d4c
Apply contribution guidelines to "StringVal" rule
Also creates a "ToStringStub" class to help on testing objects that can
be converted to string.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-06 08:41:12 +02:00

37 lines
889 B
PHP

--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Exceptions\StringValException;
use Respect\Validation\Validator as v;
try {
v::stringVal()->check([]);
} catch (StringValException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::not(v::stringVal())->check(true);
} catch (StringValException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::stringVal()->assert(new stdClass());
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
try {
v::not(v::stringVal())->assert(42);
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
?>
--EXPECTF--
`{ }` must be a string
`TRUE` must not be string
- `[object] (stdClass: { })` must be a string
- 42 must not be string