respect-validation/tests/integration/transformers/deprecated_attribute.phpt
Henrique Moody 97b243daa1
Allow building rules using prefixes
Although helpful, the changes in the Min, Max, and Length rules made
using those rules more verbose. This commit will simplify their use by
allowing users to use them as prefixes.

Because I was creating prefixes for those rules, I made other cool
prefixes. Doing that is scary because it will generate more code to
support, and I would have liked to avoid that. However, that's a
valuable addition, and it's worth the risk.

I might reconsider that in the future, but for now, that looks like a
good idea.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-24 16:58:24 +01:00

49 lines
2.2 KiB
PHP

--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
$object = new stdClass();
$object->foo = true;
$object->bar = 42;
exceptionMessage(static fn() => v::attribute('baz')->assert($object));
exceptionMessage(static fn() => v::not(v::attribute('foo'))->assert($object));
exceptionMessage(static fn() => v::attribute('foo', v::falseVal())->assert($object));
exceptionMessage(static fn() => v::not(v::attribute('foo', v::trueVal()))->assert($object));
exceptionMessage(static fn() => v::attribute('foo', v::falseVal(), true)->assert($object));
exceptionMessage(static fn() => v::not(v::attribute('foo', v::trueVal(), true))->assert($object));
exceptionMessage(static fn() => v::attribute('foo', v::falseVal(), false)->assert($object));
exceptionMessage(static fn() => v::not(v::attribute('foo', v::trueVal(), false))->assert($object));
// phpcs:disable Generic.Files.LineLength.TooLong
?>
--EXPECTF--
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use propertyExists() instead. %s
baz must be present
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use propertyExists() instead. %s
foo must not be present
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use property() instead. %s
foo must evaluate to `false`
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use property() instead. %s
foo must not evaluate to `true`
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use property() without it. %s
foo must evaluate to `false`
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use property() without it. %s
foo must not evaluate to `true`
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use propertyOptional() instead. %s
foo must evaluate to `false`
Deprecated: The attribute() rule has been deprecated and will be removed in the next major version. Use propertyOptional() instead. %s
foo must not evaluate to `true`