[Validator] Traverse traversables#24577
Conversation
|
No test added to cover this ? This is not a good sign. bug fixes must have a test to prevent regressions |
|
@stof If you think this is indeed a bug, please give me a starting point and I'd gladly write a test. |
|
Tests are failing… if Or is it that
One is |
|
I fixed it by adding the following rule: Doctrine\Common\Collections\ArrayCollection:
getter:
values:
- Valid:
traverse: trueNot super intuitive… also the error path looks weird: |
|
This does not look like a bug to me. But we could indeed improve the documentation. @olvlvl Would you like to open a PR on https://github.com/symfony/symfony-docs? However, we could add this as a new feature in 4.1 IMO. But we would need a test and existing tests must not fail then. |
|
@xabbuh is there a way to discard the |
|
@olvlvl What would you expect instead? |
|
I expected |
|
The issue with using Traversable is that they are not all rewindable. This means validation would consume the iterator and prevent any further use of it. |
|
@nicolas-grekas You have a very good point here. How about |
|
Not all EDIT: we could do it for instances of |
|
Neither Iterator is enough, eg. Generator implements it, but is not
rewindable.
IteratorAggregate would work (and is implemented by Doctrine's Collection.)
|
|
@olvlvl ok to change to Status: needs work |
|
@nicolas-grekas So, how about I do the same in #25506? |
|
@ostrolucky doable indeed! |
|
@olvlvl OK to finish this one and add a test case ? |
|
@nicolas-grekas Sorry I've been quite busy. I'll try to work on it today. |
|
ping @olvlvl :) |
7b08244 to
bd97f6c
Compare
bd97f6c to
9ca0c49
Compare
|
Hi @nicolas-grekas, I wrote a test to validate an instance of a class implementing I had no fun writing these few lines of code. The only documentation I found regarding object validation that do not involve annotation shenanigans was in this issue: #11895 (comment). |
Instances such as Doctrine's collections are not traversed because the condition is
is_array(). This PR checks for\Traversabletoo.I was trying to validate the following:
But it kept failing because
servingsis aArrayCollection, not anarray.I'm targeting v2.8 but this goes all the way to master. I'm using v3.4.