respect-validation/tests/feature/AssertWithPropertiesTest.php
2025-12-18 19:03:39 +01:00

50 lines
1.5 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
test('Scenario #1', catchFullMessage(
fn() => 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(json_decode((string) json_encode([
'mysql' => [
'host' => 42,
'user' => 'user',
'password' => 'password',
'schema' => 'schema',
],
'postgresql' => [
'host' => 'host',
'user' => 42,
'password' => 'password',
'schema' => 'schema',
],
]))),
fn(string $fullMessage) => expect($fullMessage)->toBe(<<<'FULL_MESSAGE'
- the given data must pass all the rules
- `.mysql` must pass the rules
- `.host` must be a string
- `.postgresql` must pass the rules
- `.user` must be a string
FULL_MESSAGE),
));