respect-validation/tests/integration/keys_as_validator_names.phpt
Henrique Moody 9eafe52252
Refactor the Length rule
Currently, the Length rule does multiple things, yet it's limited.
Because it does many things, it's also confusing. Turning the Length
rule into a transformation allows for way more flexibility and clarity.

The syntax becomes more verbose, but I can solve that later by creating
a Transformer enables creating rules with the "length" as a prefix.

While making this change, I also removed the support for counting
objects and integers. I find that way too confusing.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-19 15:38:29 +01:00

24 lines
623 B
PHP

--FILE--
<?php
declare(strict_types=1);
date_default_timezone_set('UTC');
require 'vendor/autoload.php';
use Respect\Validation\Validator;
exceptionFullMessage(static function (): void {
Validator::create()
->key('username', Validator::length(Validator::between(2, 32)))
->key('birthdate', Validator::dateTime())
->setName('User Subscription Form')
->assert(['username' => '0', 'birthdate' => 'Whatever']);
});
?>
--EXPECT--
- All of the required rules must pass for User Subscription Form
- The length of username must be between 2 and 32
- birthdate must be a valid date/time