Skip to content

[Validator] Testing compound constraints #50205

@derrabus

Description

@derrabus

Description

Symfony allows to compose constraints out of constraints using the Compound base class. This is a great tool for cases where a custom validator would be overkill. However, I think we're lacking a nice way to test these compounds. The documentation of compounds does not explain how to test them either.

There is a ConstraintValidatorTestCase class that can be used for custom validators, but that class does not work on compounds because it creates a fully mocked validator that would not delegate the validation to the proper validators for the constraints that the compound is composed of.

Currently, I'm running a functional test (using KernelTestCase) to test compounds but that boots the whole kernel (which feels unnecessary) and lacks the tooling that ConstraintValidatorTestCase provides to assert expected violations.

It would be nice to have a CompoundConstraintTestCase that works like ConstraintValidatorTestCase but would allow the delegating calls to the individual validators.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions