respect-validation/tests/integration/transformers/deprecated_keyNested.phpt
Henrique Moody 9322cd6375
Do not create results with siblings in the When rule
When creating a result with a sibling in the When rule, the result
generates an unhelpful message. In most of the use cases of the When
rule, the initial rule ("when") is only helpful in determining which
will be the "real" rule to use.

Those changes will change the When rule not to generate results with
siblings.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-25 23:47:25 +01:00

50 lines
2.2 KiB
PHP

--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
$input = [
'foo' => (object) [
'bar' => 123,
],
];
exceptionMessage(static fn() => v::keyNested('foo.bar.baz')->assert(['foo.bar.baz' => false]));
exceptionMessage(static fn() => v::keyNested('foo.bar')->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar')->assert(new ArrayObject($input)));
exceptionMessage(static fn() => v::keyNested('foo.bar', v::negative())->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar')->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar', v::stringType())->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar.baz', v::notEmpty(), false)->assert($input));
exceptionMessage(static fn() => v::keyNested('foo.bar', v::floatType(), false)->assert($input));
?>
--EXPECTF--
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
foo must be present
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
No exception was thrown
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
No exception was thrown
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
bar must be negative
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
No exception was thrown
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
bar must be of type string
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
No exception was thrown
Deprecated: The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead. in %s
bar must be of type float