mirror of
https://github.com/Respect/Validation.git
synced 2024-06-28 02:00:06 +02:00
Currently, the Property rule has a third parameter that allows the validation of the wrapped rule to be optional, meaning that the validation will only happen if the property exists. That parameter makes the rule harder to understand at times. I'm splitting the Property rule into Property, PropertyExists, and PropertyOptional. That way, it becomes apparent when someone wants only to validate whether a property exists or if they will validate the value of the property only when it exists. I deliberately didn't create an abstract class because those rules are different enough not to have an abstraction. In fact, I can see myself deleting the AbstractRelated after I refactor the KeyNested rule. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
exceptionFullMessage(static function (): void {
|
|
$array = [
|
|
'mysql' => [
|
|
'host' => 42,
|
|
'user' => 'user',
|
|
'password' => 'password',
|
|
'schema' => 'schema',
|
|
],
|
|
'postgresql' => [
|
|
'host' => 'host',
|
|
'user' => 42,
|
|
'password' => 'password',
|
|
'schema' => 'schema',
|
|
],
|
|
];
|
|
$object = json_decode((string) json_encode($array));
|
|
v::create()
|
|
->property(
|
|
'mysql',
|
|
v::create()
|
|
->property('host', v::stringType())
|
|
->property('user', v::stringType())
|
|
->property('password', v::stringType())
|
|
->property('schema', v::stringType())
|
|
)
|
|
->property(
|
|
'postgresql',
|
|
v::create()
|
|
->property('host', v::stringType())
|
|
->property('user', v::stringType())
|
|
->property('password', v::stringType())
|
|
->property('schema', v::stringType())
|
|
)
|
|
->setName('the given data')
|
|
->assert($object);
|
|
});
|
|
?>
|
|
--EXPECT--
|
|
- All of the required rules must pass for the given data
|
|
- These rules must pass for mysql
|
|
- host must be of type string
|
|
- These rules must pass for postgresql
|
|
- user must be of type string
|