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

39 lines
1.6 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
test('https://github.com/Respect/Validation/issues/1376', catchAll(
fn() => v::create()
->property('title', v::lengthBetween(2, 3)->stringType())
->property('description', v::stringType())
->property('author', v::intType()->lengthBetween(1, 2))
->property('user', v::intVal()->lengthBetween(1, 2))
->assert((object) ['author' => 'foo']),
fn(string $message, string $fullMessage, array $messages) => expect()
->and($message)->toBe('`.title` must be present')
->and($fullMessage)->toBe(<<<'FULL_MESSAGE'
- `stdClass { +$author="foo" }` must pass all the rules
- `.title` must be present
- `.description` must be present
- `.author` must pass all the rules
- `.author` must be an integer
- The length of `.author` must be between 1 and 2
- `.user` must be present
FULL_MESSAGE)
->and($messages)->toBe([
'__root__' => '`stdClass { +$author="foo" }` must pass all the rules',
'title' => '`.title` must be present',
'description' => '`.description` must be present',
'author' => [
'__root__' => '`.author` must pass all the rules',
'intType' => '`.author` must be an integer',
'lengthBetween' => 'The length of `.author` must be between 1 and 2',
],
'user' => '`.user` must be present',
]),
));