respect-validation/tests/integration/rules/instance.phpt
Danilo Benevides d022a71f54
Apply contribution guidelines to "Instance" rule
Also updates how the tests define the name of the instance by using the
class keyword [1] instead of a string with the class. That is useful
in code analyses be able to identify the usage of these
classes/interfaces.

[1] http://php.net/class#language.oop5.basic.class.class

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
2018-08-16 21:54:17 +02:00

37 lines
1.1 KiB
PHP

--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Exceptions\InstanceException;
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Validator as v;
try {
v::instance(DateTime::class)->check('');
} catch (InstanceException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::not(v::instance(Traversable::class))->check(new \ArrayObject());
} catch (InstanceException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::instance(ArrayIterator::class)->assert(new stdClass());
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
try {
v::not(v::instance(stdClass::class))->assert(new stdClass());
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
?>
--EXPECTF--
"" must be an instance of "DateTime"
`[traversable] (ArrayObject: { })` must not be an instance of "Traversable"
- `[object] (stdClass: { })` must be an instance of "ArrayIterator"
- `[object] (stdClass: { })` must not be an instance of "stdClass"