Skip to content

Validation multiple. #165

@terabytesoftw

Description

@terabytesoftw

Rules FormModel:

public function getRules(): array
{
    return [
        'id' => [Number::rule(), HasLength::rule()->min(2)->tooShortMessage('Its to short.')],
        'names' => [Each::rule(new RuleSet([HasLength::rule()->max(10)]))],
   ];
}

Test validator:

public function testEachMultiple(): void
{
    $eachForm = new EachForm();
    $validator = $this->createValidatorMock();

    $eachForm->setAttribute('id', 'a');
    $eachForm->setAttribute('names', ['wilmer', 'pedrovitelek', 'samdark']);
    $result = $validator->validate($eachForm);
}

Show error message:

    'id' => ["Value must be a number."]

Expected error message:

    'id' => ["Value must be a number.", "Its to short."]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions