Skip to content

[Validator] Invalid All constraint tests succeed #51416

Closed
@adrianrudnik

Description

@adrianrudnik

Symfony version(s) affected

6.4

Description

While building a custom constraint similar to All (based on a Composite) for a custom DBAL type I never get the validator to actually fail in tests. I tried to get some feedback in the discussions, but it just looks like an issue.

Not sure if test-only PRs would be OK if they do not solve the issue, so I just did this issue.

Looking through the AllValidatorTest it seems that not a single ->assertNoViolation() of this test can be trusted or procudes what I would expect, it just asserts that everything is fine, which is somehow always true.

There are also no additional bad-path tests for this validator. Is this expected, or am I missing something?

How to reproduce

I've added an enhanced test in a branch, with a single commit testing a Range constraint violation.

Tests run with

php ./phpunit src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php --testdox

Possible Solution

Looking at the other Composite based validator test AtLeastOneOfValidatorTest there is a stark contrast in both tests and how thorough they are. I'm sadly not very proficient with ConstraintValidatorTestCase to fully grasp the other test to derive a better test for the All constraint.

Also I'm not sure if the usage without array notation for the constraints like in testNullIsValid and testThrowsExceptionIfNotTraversable is actually good practice.

Additional Context

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